new models
This commit is contained in:
parent
5b16cc60f7
commit
f87a759048
123
prisma/migrations/20240904083737_new_defaults/migration.sql
Normal file
123
prisma/migrations/20240904083737_new_defaults/migration.sql
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `authorId` on the `Publication` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `data` on the `Publication` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `originalId` on the `Schema` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `schema` on the `Schema` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `types` on the `Schema` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `version` on the `Schema` table. All the data in the column will be lost.
|
||||
- You are about to drop the `TagsOnPublications` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `TagsOnTags` table. If the table is not empty, all the data it contains will be lost.
|
||||
- Added the required column `schemaVersion` to the `Publication` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `publicationRevisionId` to the `Tag` table without a default value. This is not possible if the table is not empty.
|
||||
- Made the column `publicationId` on table `Tag` required. This step will fail if there are existing NULL values in that column.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Publication" DROP CONSTRAINT "Publication_authorId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Tag" DROP CONSTRAINT "Tag_publicationId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "TagsOnPublications" DROP CONSTRAINT "TagsOnPublications_publicationId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "TagsOnPublications" DROP CONSTRAINT "TagsOnPublications_tagId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "TagsOnTags" DROP CONSTRAINT "TagsOnTags_childTagId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "TagsOnTags" DROP CONSTRAINT "TagsOnTags_parentTagId_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "GameSystem" ADD COLUMN "isPublic" BOOLEAN NOT NULL DEFAULT false;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Publication" DROP COLUMN "authorId",
|
||||
DROP COLUMN "data",
|
||||
ADD COLUMN "schemaVersion" INTEGER NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Schema" DROP COLUMN "originalId",
|
||||
DROP COLUMN "schema",
|
||||
DROP COLUMN "types",
|
||||
DROP COLUMN "version";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Tag" ADD COLUMN "publicationRevisionId" TEXT NOT NULL,
|
||||
ALTER COLUMN "publicationId" SET NOT NULL;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "TagsOnPublications";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "TagsOnTags";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "SchemaRevision" (
|
||||
"id" TEXT NOT NULL,
|
||||
"schemaId" TEXT NOT NULL,
|
||||
"fields" JSONB NOT NULL DEFAULT '{}',
|
||||
"types" JSONB NOT NULL DEFAULT '{}',
|
||||
"version" INTEGER NOT NULL DEFAULT 0,
|
||||
"isFinal" BOOLEAN NOT NULL DEFAULT false,
|
||||
|
||||
CONSTRAINT "SchemaRevision_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "PublicationRevision" (
|
||||
"id" TEXT NOT NULL,
|
||||
"previousId" TEXT,
|
||||
"publicationId" TEXT NOT NULL,
|
||||
"authorId" TEXT NOT NULL,
|
||||
"version" TEXT NOT NULL,
|
||||
"isFinal" BOOLEAN NOT NULL DEFAULT false,
|
||||
"data" JSONB NOT NULL DEFAULT '{}',
|
||||
|
||||
CONSTRAINT "PublicationRevision_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "GameSystemFollows" (
|
||||
"gameSystemId" TEXT NOT NULL,
|
||||
"userId" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "GameSystemFollows_pkey" PRIMARY KEY ("userId","gameSystemId")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "SchemaRevision_schemaId_version_key" ON "SchemaRevision"("schemaId", "version");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "PublicationRevision_publicationId_version_key" ON "PublicationRevision"("publicationId", "version");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "SchemaRevision" ADD CONSTRAINT "SchemaRevision_schemaId_fkey" FOREIGN KEY ("schemaId") REFERENCES "Schema"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Publication" ADD CONSTRAINT "Publication_schemaVersion_schemaId_fkey" FOREIGN KEY ("schemaVersion", "schemaId") REFERENCES "SchemaRevision"("version", "schemaId") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "PublicationRevision" ADD CONSTRAINT "PublicationRevision_publicationId_fkey" FOREIGN KEY ("publicationId") REFERENCES "Publication"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "PublicationRevision" ADD CONSTRAINT "PublicationRevision_previousId_fkey" FOREIGN KEY ("previousId") REFERENCES "PublicationRevision"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "PublicationRevision" ADD CONSTRAINT "PublicationRevision_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Tag" ADD CONSTRAINT "Tag_publicationId_fkey" FOREIGN KEY ("publicationId") REFERENCES "Publication"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Tag" ADD CONSTRAINT "Tag_publicationRevisionId_fkey" FOREIGN KEY ("publicationRevisionId") REFERENCES "PublicationRevision"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "GameSystemFollows" ADD CONSTRAINT "GameSystemFollows_gameSystemId_fkey" FOREIGN KEY ("gameSystemId") REFERENCES "GameSystem"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "GameSystemFollows" ADD CONSTRAINT "GameSystemFollows_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
@ -8,13 +8,15 @@ datasource db {
|
||||
}
|
||||
|
||||
model GameSystem {
|
||||
id String @id @default(cuid())
|
||||
schemas Schema[]
|
||||
author User @relation(fields: [authorId], references: [id])
|
||||
authorId String
|
||||
id String @id @default(cuid())
|
||||
schemas Schema[]
|
||||
author User @relation(fields: [authorId], references: [id])
|
||||
authorId String
|
||||
followers GameSystemFollows[]
|
||||
|
||||
name String @unique
|
||||
created DateTime @default(now())
|
||||
name String @unique
|
||||
created DateTime @default(now())
|
||||
isPublic Boolean @default(false)
|
||||
}
|
||||
|
||||
model Schema {
|
||||
@ -31,38 +33,36 @@ model Schema {
|
||||
}
|
||||
|
||||
model SchemaRevision {
|
||||
id String @id @default(cuid())
|
||||
id String @id @default(cuid())
|
||||
schemaId String
|
||||
parentSchema Schema @relation(fields: [schemaId], references: [id])
|
||||
parentSchema Schema @relation(fields: [schemaId], references: [id])
|
||||
Publication Publication[]
|
||||
|
||||
schema Json
|
||||
types Json
|
||||
version Int
|
||||
Publication Publication[]
|
||||
fields Json @default("{}")
|
||||
types Json @default("{}")
|
||||
version Int @default(0)
|
||||
isFinal Boolean @default(false)
|
||||
|
||||
@@unique([schemaId, version])
|
||||
}
|
||||
|
||||
model Publication {
|
||||
id String @id @default(cuid())
|
||||
schema Schema @relation(fields: [schemaId], references: [id])
|
||||
schemaId String
|
||||
schemaVersion Int
|
||||
schemaRevision SchemaRevision @relation(fields: [schemaVersion, schemaId], references: [version, schemaId])
|
||||
tags Tag[]
|
||||
id String @id @default(cuid())
|
||||
schema Schema @relation(fields: [schemaId], references: [id])
|
||||
schemaId String
|
||||
schemaVersion Int
|
||||
schemaRevision SchemaRevision @relation(fields: [schemaVersion, schemaId], references: [version, schemaId])
|
||||
PublicationRevision PublicationRevision[]
|
||||
tags Tag[]
|
||||
|
||||
name String
|
||||
|
||||
TagsOnPublications TagsOnPublications[]
|
||||
PublicationRevision PublicationRevision[]
|
||||
// TagsOnPublications TagsOnPublications[]
|
||||
}
|
||||
|
||||
model PublicationRevision {
|
||||
id String @id @default(cuid())
|
||||
version String
|
||||
isFinal Boolean
|
||||
data Json
|
||||
|
||||
id String @id @default(cuid())
|
||||
Tag Tag[]
|
||||
previousId String?
|
||||
publicationId String
|
||||
publication Publication @relation(fields: [publicationId], references: [id])
|
||||
@ -71,41 +71,41 @@ model PublicationRevision {
|
||||
author User @relation(fields: [authorId], references: [id])
|
||||
authorId String
|
||||
|
||||
version String
|
||||
isFinal Boolean @default(false)
|
||||
data Json @default("{}")
|
||||
|
||||
@@unique([publicationId, version])
|
||||
}
|
||||
|
||||
model TagsOnPublications {
|
||||
publication Publication @relation(fields: [publicationId], references: [id])
|
||||
publicationId String
|
||||
tagId String
|
||||
tag Tag @relation(fields: [tagId], references: [id])
|
||||
// model TagsOnPublications {
|
||||
// publication Publication @relation(fields: [publicationId], references: [id])
|
||||
// publicationId String
|
||||
// tagId String
|
||||
// tag Tag @relation(fields: [tagId], references: [id])
|
||||
|
||||
@@id([publicationId, tagId])
|
||||
}
|
||||
// @@id([publicationId, tagId])
|
||||
// }
|
||||
|
||||
model Tag {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
Publication Publication? @relation(fields: [publicationId], references: [id])
|
||||
publicationId String?
|
||||
TagsOnPublications TagsOnPublications[]
|
||||
childTagsOnTags TagsOnTags[] @relation("childTag")
|
||||
parentTagsOnTags TagsOnTags[] @relation("parentTag")
|
||||
}
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
Publication Publication @relation(fields: [publicationId], references: [id])
|
||||
publicationId String
|
||||
PublicationRevision PublicationRevision @relation(fields: [publicationRevisionId], references: [id])
|
||||
publicationRevisionId String
|
||||
|
||||
model TagsOnTags {
|
||||
parentTagId String
|
||||
parentTag Tag @relation(fields: [parentTagId], references: [id], "parentTag")
|
||||
childTagId String
|
||||
childTag Tag @relation(fields: [childTagId], references: [id], "childTag")
|
||||
|
||||
@@id([parentTagId, childTagId])
|
||||
// TagsOnPublications TagsOnPublications[]
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(cuid())
|
||||
schemas Schema[]
|
||||
gameSystems GameSystem[]
|
||||
id String @id @default(cuid())
|
||||
schemas Schema[]
|
||||
gameSystems GameSystem[]
|
||||
accounts Account[]
|
||||
sessions Session[]
|
||||
PublicationRevision PublicationRevision[]
|
||||
followedSystems GameSystemFollows[]
|
||||
|
||||
name String?
|
||||
username String? @unique
|
||||
@ -113,12 +113,18 @@ model User {
|
||||
emailVerified DateTime?
|
||||
passwordHash String?
|
||||
image String?
|
||||
accounts Account[]
|
||||
sessions Session[]
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
PublicationRevision PublicationRevision[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model GameSystemFollows {
|
||||
gameSystemId String
|
||||
gameSystem GameSystem @relation(fields: [gameSystemId], references: [id])
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
|
||||
@@id([userId, gameSystemId])
|
||||
}
|
||||
|
||||
model Account {
|
||||
|
2
types.d.ts
vendored
2
types.d.ts
vendored
@ -83,7 +83,7 @@ type SchemaTypes = Record<string, TypeType>;
|
||||
type Schema = {
|
||||
id: string;
|
||||
name: string;
|
||||
schema: SchemaFields;
|
||||
fields: SchemaFields;
|
||||
types: SchemaTypes;
|
||||
gameSystemId?: string;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user