Some checks failed
Deploy analytics worker / Deploy analytics worker to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
i18n upload strings / Upload latest strings (push) Failing after 1s
Deploy bemo / Deploy bemo to ${{ (github.ref == 'refs/heads/bemo-production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
Deploy grafana resources / ${{ github.event_name == 'push' && 'Deploy grafana resources' || 'Validate grafana resources (dry run)' }} (push) Failing after 0s
End to end tests (dotcom) / Check for relevant changes (push) Failing after 0s
End to end tests (examples) / Check for relevant changes (push) Failing after 0s
End to end tests (mermaid readability) / Check for relevant changes (push) Failing after 1s
End to end tests (perf) / Check for relevant changes (push) Failing after 0s
Publish editor extensions / Publish editor extensions (push) Failing after 1s
Publish SDK packages / Remove the publish-packages label (push) Has been skipped
Checks / Tests & checks (push) Has been cancelled
Checks / Build all projects (push) Has been cancelled
Deploy templates / Deploy templates (push) Has been cancelled
End to end tests (dotcom) / End to end tests (dotcom) (push) Has been cancelled
End to end tests (mermaid readability) / End to end tests (mermaid readability) (push) Has been cancelled
End to end tests (perf) / End to end tests (perf) (push) Has been cancelled
Deploy .com / Deploy dotcom to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Has been cancelled
End to end tests (examples) / End to end tests (examples) (push) Has been cancelled
Publish SDK packages / Publish SDK packages (push) Has been cancelled
Publish SDK packages / Tell user released version (push) Has been cancelled
Publish SDK packages / Publishes code templates to separate repositories (push) Has been cancelled
Publish SDK packages / Deploys the template demos with the new SDK version (push) Has been cancelled
72 lines
2.0 KiB
PL/PgSQL
72 lines
2.0 KiB
PL/PgSQL
CREATE TABLE "user" (
|
|
"id" VARCHAR PRIMARY KEY,
|
|
"name" VARCHAR NOT NULL,
|
|
"email" VARCHAR NOT NULL,
|
|
"avatar" VARCHAR NOT NULL,
|
|
"color" VARCHAR NOT NULL,
|
|
"exportFormat" VARCHAR NOT NULL,
|
|
"exportTheme" VARCHAR NOT NULL,
|
|
"exportBackground" BOOLEAN NOT NULL,
|
|
"exportPadding" BOOLEAN NOT NULL,
|
|
"createdAt" BIGINT NOT NULL,
|
|
"updatedAt" BIGINT NOT NULL,
|
|
"flags" VARCHAR NOT NULL,
|
|
"locale" VARCHAR,
|
|
"animationSpeed" BIGINT,
|
|
"edgeScrollSpeed" BIGINT,
|
|
"colorScheme" VARCHAR,
|
|
"isSnapMode" BOOLEAN,
|
|
"isWrapMode" BOOLEAN,
|
|
"isDynamicSizeMode" BOOLEAN,
|
|
"isPasteAtCursorMode" BOOLEAN
|
|
);
|
|
|
|
CREATE TABLE "file" (
|
|
"id" VARCHAR PRIMARY KEY,
|
|
"name" VARCHAR NOT NULL,
|
|
"ownerId" VARCHAR NOT NULL,
|
|
"thumbnail" VARCHAR NOT NULL,
|
|
"shared" BOOLEAN NOT NULL,
|
|
"sharedLinkType" VARCHAR NOT NULL,
|
|
"published" BOOLEAN NOT NULL,
|
|
"lastPublished" BIGINT NOT NULL,
|
|
"publishedSlug" VARCHAR NOT NULL,
|
|
"createdAt" BIGINT NOT NULL,
|
|
"updatedAt" BIGINT NOT NULL,
|
|
"isEmpty" BOOLEAN NOT NULL,
|
|
FOREIGN KEY ("ownerId") REFERENCES "user" ("id") ON DELETE CASCADE
|
|
);
|
|
|
|
CREATE TABLE "file_state" (
|
|
"userId" VARCHAR NOT NULL,
|
|
"fileId" VARCHAR NOT NULL,
|
|
"firstVisitAt" BIGINT,
|
|
"lastEditAt" BIGINT,
|
|
"lastSessionState" VARCHAR,
|
|
"lastVisitAt" BIGINT,
|
|
PRIMARY KEY ("userId", "fileId"),
|
|
FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE,
|
|
FOREIGN KEY ("fileId") REFERENCES "file" ("id") ON DELETE CASCADE
|
|
);
|
|
|
|
CREATE TABLE "user_mutation_number" (
|
|
"userId" VARCHAR NOT NULL PRIMARY KEY,
|
|
"mutationNumber" BIGINT NOT NULL
|
|
);
|
|
|
|
CREATE PUBLICATION alltables FOR ALL TABLES;
|
|
|
|
CREATE OR REPLACE FUNCTION delete_file_states() RETURNS TRIGGER AS $$
|
|
BEGIN
|
|
IF OLD.shared = TRUE AND NEW.shared = FALSE THEN
|
|
DELETE FROM file_state WHERE "fileId" = OLD.id AND OLD."ownerId" != "userId";
|
|
END IF;
|
|
RETURN NEW;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
-- Step 2: Create the trigger
|
|
CREATE TRIGGER file_shared_update
|
|
AFTER UPDATE OF shared ON file
|
|
FOR EACH ROW
|
|
EXECUTE FUNCTION delete_file_states(); |