diff --git a/packages/server/package.json b/packages/server/package.json index e19c6a5..e8cf729 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -16,6 +16,7 @@ "nodemon": "^3.0.1", "prettier": "^3.0.1", "prisma": "^5.3.1", + "prisma-dbml-generator": "^0.12.0", "ts-node": "^10.9.1", "typescript": "^5.1.6" }, diff --git a/packages/server/prisma/dbml/schema.dbml b/packages/server/prisma/dbml/schema.dbml new file mode 100644 index 0000000..8924f50 --- /dev/null +++ b/packages/server/prisma/dbml/schema.dbml @@ -0,0 +1,96 @@ +//// ------------------------------------------------------ +//// THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY) +//// ------------------------------------------------------ + +Table User { + sub String [pk] + lastPixelTime DateTime [default: `now()`, not null] + pixels Pixel [not null] + FactionMember FactionMember [not null] +} + +Table PalleteColor { + id Int [pk, increment] + name String [not null] + hex String [unique, not null] + pixels Pixel [not null] +} + +Table Pixel { + id Int [pk, increment] + userId String [not null] + x Int [not null] + y Int [not null] + color String [not null] + createdAt DateTime [default: `now()`, not null] + user User [not null] + pallete PalleteColor [not null] +} + +Table Faction { + id String [pk] + name String [not null] + image String + FactionMember FactionMember [not null] + FactionRole FactionRole [not null] + FactionSocial FactionSocial [not null] + FactionSetting FactionSetting [not null] +} + +Table FactionMember { + id Int [pk, increment] + sub String [not null] + factionId String [not null] + user User [not null] + faction Faction [not null] +} + +Table FactionRole { + id String [pk] + name String [not null] + level Int [not null] + factionId String [not null] + faction Faction [not null] +} + +Table FactionSocial { + id String [pk] + factionId String [not null] + title String + url String [not null] + position Int [not null] + faction Faction [not null] +} + +Table FactionSetting { + id String [pk] + factionId String [not null] + key String [not null] + value String [not null] + definition FactionSettingDefinition [not null] + faction Faction [not null] +} + +Table FactionSettingDefinition { + id String [pk] + name String [not null] + type String [not null] + minimumLevel Int [not null] + FactionSetting FactionSetting [not null] +} + +Ref: Pixel.userId > User.sub + +Ref: Pixel.color > PalleteColor.hex + +Ref: FactionMember.sub > User.sub + +Ref: FactionMember.factionId > Faction.id + +Ref: FactionRole.factionId > Faction.id + +Ref: FactionSocial.factionId > Faction.id + +Ref: FactionSetting.key > FactionSettingDefinition.id + +Ref: FactionSetting.factionId > Faction.id \ No newline at end of file diff --git a/packages/server/prisma/schema.prisma b/packages/server/prisma/schema.prisma index 6e0d7ce..169b49c 100644 --- a/packages/server/prisma/schema.prisma +++ b/packages/server/prisma/schema.prisma @@ -5,6 +5,10 @@ generator client { provider = "prisma-client-js" } +generator dbml { + provider = "prisma-dbml-generator" +} + datasource db { provider = "sqlite" url = env("DATABASE_URL") @@ -14,7 +18,8 @@ model User { sub String @id lastPixelTime DateTime @default(now()) - pixels Pixel[] + pixels Pixel[] + FactionMember FactionMember[] } model PalleteColor { @@ -37,3 +42,64 @@ model Pixel { user User @relation(fields: [userId], references: [sub]) pallete PalleteColor @relation(fields: [color], references: [hex]) } + +model Faction { + id String @id @default(uuid()) + name String + image String? + + FactionMember FactionMember[] + FactionRole FactionRole[] + FactionSocial FactionSocial[] + FactionSetting FactionSetting[] +} + +// people can be apart of multiple factions at once +model FactionMember { + id Int @id @default(autoincrement()) + sub String + factionId String + + user User @relation(fields: [sub], references: [sub]) + faction Faction @relation(fields: [factionId], references: [id]) +} + +// future proofing maybe: different roles for the same faction +// factions by default should have LEADER, MODERATOR, MEMBER +model FactionRole { + id String @id @default(uuid()) + name String + level Int // permission level (similar to matrix [0 = member, 100 = leader]) + factionId String + + faction Faction @relation(fields: [factionId], references: [id]) +} + +model FactionSocial { + id String @id @default(uuid()) + factionId String + title String? // display name for the link + url String // [!] rel=nofollow [!] + position Int + + faction Faction @relation(fields: [factionId], references: [id]) +} + +model FactionSetting { + id String @id @default(uuid()) + factionId String + key String + value String + + definition FactionSettingDefinition @relation(fields: [key], references: [id]) + faction Faction @relation(fields: [factionId], references: [id]) +} + +// global definition for the faction setting +model FactionSettingDefinition { + id String @id + name String + type String // enum of type of setting (eg. text, checkbox) + minimumLevel Int // what level is needed to modify this setting (>=) + FactionSetting FactionSetting[] +}