diff --git a/README.md b/README.md index e5030f5..808f462 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,17 @@ Communication server using the Nexlink protocol ### Install dependencies - npm install -### Set up and start postgres database +### Set up and start postgres database (docker) - docker compose pull - docker compose up +### Set up and start postgres database (podman) +- podman-compose pull +- podman-compose up + +### Set up .env file and fill in the environment variables +- cp env .env + ### Create database migrations - npx prisma migrate dev diff --git a/env b/env index 0b481ec..5534241 100644 --- a/env +++ b/env @@ -1 +1,2 @@ DATABASE_URL="postgresql://tetheruser:password@localhost:5432/tetherdb" +JWT_SECRET="" diff --git a/prisma/migrations/20251224120739_invites/migration.sql b/prisma/migrations/20251224120739_invites/migration.sql new file mode 100644 index 0000000..167cdc0 --- /dev/null +++ b/prisma/migrations/20251224120739_invites/migration.sql @@ -0,0 +1,17 @@ +-- CreateTable +CREATE TABLE "Invite" ( + "id" TEXT NOT NULL, + "communityId" TEXT, + "totalInvites" INTEGER NOT NULL DEFAULT 0, + "remainingInvites" INTEGER NOT NULL DEFAULT 0, + "creationDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "expirationDate" TIMESTAMP(3), + + CONSTRAINT "Invite_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "Invite_id_key" ON "Invite"("id"); + +-- AddForeignKey +ALTER TABLE "Invite" ADD CONSTRAINT "Invite_communityId_fkey" FOREIGN KEY ("communityId") REFERENCES "Community"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 85162b6..06673fb 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1,53 +1,64 @@ generator client { - provider = "prisma-client" - output = "../src/generated/prisma" - engineType = "client" + provider = "prisma-client" + output = "../src/generated/prisma" + engineType = "client" } datasource db { - provider = "postgresql" + provider = "postgresql" } model Community { - id String @id @unique @default(uuid()) - name String @unique - description String? - members User[] - Channel Channel[] - Role Role[] + id String @id @unique @default(uuid()) + name String @unique + description String? + members User[] + Channel Channel[] + Role Role[] + invites Invite[] } model Channel { - id String @id @unique @default(uuid()) - name String? - community Community? @relation(fields: [communityId], references: [id]) - communityId String? + id String @id @unique @default(uuid()) + name String? + community Community? @relation(fields: [communityId], references: [id]) + communityId String? } model Role { - id String @id @unique @default(uuid()) - name String? - community Community @relation(fields: [communityId], references: [id]) - communityId String + id String @id @unique @default(uuid()) + name String? + community Community @relation(fields: [communityId], references: [id]) + communityId String } model User { - id String @id @unique @default(uuid()) - username String @unique - email String? @unique - passwordHash String? - description String? - admin Boolean @default(false) - registerDate DateTime @default(now()) - lastLogin DateTime? - Community Community? @relation(fields: [communityId], references: [id]) - communityId String? - Session Session[] + id String @id @unique @default(uuid()) + username String @unique + email String? @unique + passwordHash String? + description String? + admin Boolean @default(false) + registerDate DateTime @default(now()) + lastLogin DateTime? + Community Community? @relation(fields: [communityId], references: [id]) + communityId String? + Session Session[] } model Session { - id String @id @unique @default(uuid()) - owner User @relation(fields: [userId], references: [id]) - token String - userId String + id String @id @unique @default(uuid()) + owner User @relation(fields: [userId], references: [id]) + token String + userId String +} + +model Invite { + id String @id @unique @default(uuid()) + Community Community? @relation(fields: [communityId], references: [id]) + communityId String? + totalInvites Int @default(0) + remainingInvites Int @default(0) + creationDate DateTime @default(now()) + expirationDate DateTime? }