diff --git a/apps/zbugs/docker/init_upstream/init.sql b/apps/zbugs/docker/init_upstream/init.sql index 478dad2dc..e292e0c5a 100644 --- a/apps/zbugs/docker/init_upstream/init.sql +++ b/apps/zbugs/docker/init_upstream/init.sql @@ -7,6 +7,8 @@ DROP TABLE IF EXISTS "user", "userPref", "zero.schemaVersions" CASCADE; +-- user + CREATE TABLE "user" ( "id" VARCHAR PRIMARY KEY, "login" VARCHAR NOT NULL, @@ -19,19 +21,51 @@ CREATE TABLE "user" ( CREATE UNIQUE INDEX user_login_idx ON "user" (login); CREATE UNIQUE INDEX user_githubid_idx ON "user" ("githubID"); +-- issue + CREATE TABLE issue ( "id" VARCHAR PRIMARY KEY, "shortID" INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 3000), - "title" VARCHAR NOT NULL, + "title" VARCHAR(128) NOT NULL, "open" BOOLEAN NOT NULL, "modified" double precision DEFAULT (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000), "created" double precision DEFAULT (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000), "creatorID" VARCHAR REFERENCES "user"(id) NOT NULL, "assigneeID" VARCHAR REFERENCES "user"(id), - "description" TEXT DEFAULT '', + -- Size chosen because max we currently have in legacy data is ~9KB. + "description" VARCHAR(10240) DEFAULT '', "visibility" VARCHAR DEFAULT 'public' NOT NULL ); + +CREATE OR REPLACE FUNCTION update_modified_column() +RETURNS TRIGGER AS $$ +BEGIN + NEW.modified = (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000); + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER issue_set_last_modified +BEFORE INSERT OR UPDATE ON issue +FOR EACH ROW +EXECUTE FUNCTION update_modified_column(); + +CREATE OR REPLACE FUNCTION issue_set_created_on_insert() +RETURNS TRIGGER AS $$ +BEGIN + NEW.created = (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000); + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER issue_set_created_on_insert_trigger +BEFORE INSERT ON issue +FOR EACH ROW +EXECUTE FUNCTION issue_set_created_on_insert(); + +-- viewState + CREATE TABLE "viewState" ( "userID" VARCHAR REFERENCES "user"(id) ON DELETE CASCADE, "issueID" VARCHAR REFERENCES issue(id) ON DELETE CASCADE, @@ -39,6 +73,8 @@ CREATE TABLE "viewState" ( PRIMARY KEY ("userID", "issueID") ); +-- comment + CREATE TABLE comment ( id VARCHAR PRIMARY KEY, "issueID" VARCHAR REFERENCES issue(id) ON DELETE CASCADE, @@ -75,17 +111,46 @@ BEFORE INSERT ON comment FOR EACH ROW EXECUTE FUNCTION comment_set_created_on_insert(); +CREATE OR REPLACE FUNCTION validate_comment_body_length() +RETURNS TRIGGER AS $$ +BEGIN + IF NEW.body IS NOT NULL THEN + -- The launch post has a special case maxlength of 1024 because trolls + IF NEW."issueID" = 'duuW9Nyj5cTNLlimp9Qje' AND LENGTH(NEW.body) > 1024 THEN + RAISE EXCEPTION 'Column value exceeds maximum allowed length of %', 1024; + END IF; + -- Length chosen because we have some old comments that are ~44KB. + IF LENGTH(NEW.body) > 64*1024 THEN + RAISE EXCEPTION 'Column value exceeds maximum allowed length of %', 64*1024; + END IF; + END IF; + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER check_comment_body_length +BEFORE INSERT OR UPDATE ON comment +FOR EACH ROW +EXECUTE FUNCTION validate_comment_body_length(); + + +-- label + CREATE TABLE label ( "id" VARCHAR PRIMARY KEY, "name" VARCHAR NOT NULL ); +-- issueLabel + CREATE TABLE "issueLabel" ( "labelID" VARCHAR REFERENCES label(id), "issueID" VARCHAR REFERENCES issue(id) ON DELETE CASCADE, PRIMARY KEY ("labelID", "issueID") ); +-- emoji + CREATE TABLE emoji ( "id" VARCHAR PRIMARY KEY, "value" VARCHAR NOT NULL, @@ -181,6 +246,8 @@ BEGIN END; $$ LANGUAGE plpgsql; +-- userPref + CREATE TABLE "userPref" ( "key" VARCHAR NOT NULL, "value" VARCHAR NOT NULL, @@ -189,6 +256,8 @@ CREATE TABLE "userPref" ( PRIMARY KEY ("userID", "key") ); +-- zero.schemaVersions + CREATE SCHEMA IF NOT EXISTS zero; CREATE TABLE IF NOT EXISTS zero."schemaVersions" ( @@ -206,34 +275,6 @@ INSERT INTO zero."schemaVersions" ("lock", "minSupportedVersion", "maxSupportedV VALUES (true, 3, 5) ON CONFLICT DO NOTHING; --- last modified function and trigger -CREATE OR REPLACE FUNCTION update_modified_column() -RETURNS TRIGGER AS $$ -BEGIN - NEW.modified = (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000); - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE TRIGGER issue_set_last_modified -BEFORE INSERT OR UPDATE ON issue -FOR EACH ROW -EXECUTE FUNCTION update_modified_column(); - -CREATE OR REPLACE FUNCTION issue_set_created_on_insert() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created = (EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000); - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE TRIGGER issue_set_created_on_insert_trigger -BEFORE INSERT ON issue -FOR EACH ROW -EXECUTE FUNCTION issue_set_created_on_insert(); - - COPY "user" FROM '/docker-entrypoint-initdb.d/users.csv' WITH CSV HEADER; @@ -254,6 +295,7 @@ COPY "comment" FROM '/docker-entrypoint-initdb.d/comments.csv' WITH CSV HEADER; + -- Create the indices on upstream so we can copy to downstream on replication. -- We have discussed that, in the future, the indices of the Zero replica -- can / should diverge from the indices of the upstream. This is because diff --git a/apps/zbugs/docker/init_upstream/issues.csv b/apps/zbugs/docker/init_upstream/issues.csv index ed7063b06..c5cb6da97 100644 --- a/apps/zbugs/docker/init_upstream/issues.csv +++ b/apps/zbugs/docker/init_upstream/issues.csv @@ -3055,7 +3055,7 @@ Profile attached. More information when less tired :). [Profile-live.json.zip](https://github.com/rocicorp/reflect-server/files/9663620/Profile-live.json.zip) " -N983dAQkVWxJwlWi8nb_N,75,We can get rid of the whole complicated updateClients (which was needed due to async hashing and indexeddb). Callers can use setClients (and they need to put their own chunks).,False,1677091437000.0,1664205709000.0,nqYkxAGMnzk7Y5STjZryV,," We can get rid of the whole complicated updateClients (which was needed due to async hashing and indexeddb). Callers can use setClients (and they need to put their own chunks). +N983dAQkVWxJwlWi8nb_N,75,We can get rid of the whole complicated updateClients (which was needed due to async hashing and indexeddb)..,False,1677091437000.0,1664205709000.0,nqYkxAGMnzk7Y5STjZryV,,"Callers can use setClients (and they need to put their own chunks). Fine to do as a follow up as this is already quite a big pr. @@ -3365,10 +3365,10 @@ zrpBifgcCO7g1DjYQ1v9A,90,"Rails ""done done""",False,1677091445000.0,16570873140 - [ ] Update ReplidrawDO to use - [ ] Update Repliear to use - [ ] Rename to something else... replicache-crud?" -jC2ZSB7TCGAhDeK_CTNuj,147,Maybe call this test `crossClientGetMutationID` or something to make more clear why it only runs under DD31. A comment would also help.,False,1677091452000.0,1656407388000.0,nqYkxAGMnzk7Y5STjZryV,,"Maybe call this test `crossClientGetMutationID` or something to make more clear why it only runs under DD31. A comment would also help. +jC2ZSB7TCGAhDeK_CTNuj,147,Maybe call this test `crossClientGetMutationID` or something to make more clear why it only runs under DD31.,False,1677091452000.0,1656407388000.0,nqYkxAGMnzk7Y5STjZryV,,"A comment would also help. _Originally posted by @aboodman in https://github.com/rocicorp/replicache-internal/pull/177#discussion_r906419411_" -bbBCilPYtx_FfumPLQRqG,148,"Why not adjust these tests to have a dag.Read. Even if most of the commit types / tests don't need it, some do. Would be easier to read the test if you didn't have to understand why it's OK to pass null here.",False,1677091453000.0,1656407353000.0,nqYkxAGMnzk7Y5STjZryV,,"Why not adjust these tests to have a dag.Read. Even if most of the commit types / tests don't need it, some do. Would be easier to read the test if you didn't have to understand why it's OK to pass null here. +bbBCilPYtx_FfumPLQRqG,148,"Why not adjust these tests to have a dag.Read. Even if most of the commit types / tests don't need it, some do.",False,1677091453000.0,1656407353000.0,nqYkxAGMnzk7Y5STjZryV,,"Would be easier to read the test if you didn't have to understand why it's OK to pass null here. _Originally posted by @aboodman in https://github.com/rocicorp/replicache-internal/pull/177#discussion_r906418791_" 0aANjS4hkfgYM6jyk0bnz,111,DD 3.1,False,1709536712000.0,1655804122000.0,nqYkxAGMnzk7Y5STjZryV,,"Tracking bug for https://www.notion.so/replicache/DD-3-1-e42489fc2e6b4340a01c7fa0de353a30