From 420ba4277d8cd05998ef07f4f8fa4fd5959c1eee Mon Sep 17 00:00:00 2001 From: SunWuyuan Date: Sat, 24 May 2025 16:18:38 +0800 Subject: [PATCH] Update Dockerfile to handle database-specific commands and enhance Prisma schema for PostgreSQL and SQLite. Introduce new AccessType enum and KVStore model for improved data management. Clean up SQLite schema by removing unused fields. --- Dockerfile | 8 ++++--- prisma/database/postgres/schema.prisma | 31 ++++++++++++++++++++++++-- prisma/database/sqlite/schema.prisma | 1 - 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index ec3bfa1..410c55b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,13 +10,15 @@ ENV NODE_ENV=production \ # Copy all application files COPY . . +# Copy specific database files based on DATABASE_TYPE and clean up +RUN cp -r /prisma/database/${DATABASE_TYPE}/* /prisma/ && \ + rm -rf /prisma/database # Install dependencies and generate Prisma client RUN npm install && \ - npx prisma migrate dev --name init && \ npx prisma generate -USER node EXPOSE 3000 -CMD ["npm", "start"] +# Run different commands based on DATABASE_TYPE +CMD ["sh", "-c", "if [ \"$DATABASE_TYPE\" = \"sqlite\" ]; then (if [ ! -f /data/db.db ]; then npx prisma migrate dev --name init; else npx prisma migrate deploy; fi); else npx prisma migrate deploy; fi && npx prisma generate && npm run start"] diff --git a/prisma/database/postgres/schema.prisma b/prisma/database/postgres/schema.prisma index 02ce221..3933b8a 100644 --- a/prisma/database/postgres/schema.prisma +++ b/prisma/database/postgres/schema.prisma @@ -1,9 +1,36 @@ generator client { provider = "prisma-client-js" - output = "../generated/postgres/client" } datasource db { provider = "postgresql" url = env("DATABASE_URL") -} \ No newline at end of file +} + + +enum AccessType { + PUBLIC // No password required for read/write + PROTECTED // No password for read, password for write + PRIVATE // Password required for read/write +} + +model KVStore { + namespace String + key String + value Json + creatorIp String? @default("") + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + @@id([namespace, key]) +} + +model Device { + uuid String @id + password String? + passwordHint String? + name String? + accessType AccessType @default(PUBLIC) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt +} diff --git a/prisma/database/sqlite/schema.prisma b/prisma/database/sqlite/schema.prisma index 954085a..4dbac02 100644 --- a/prisma/database/sqlite/schema.prisma +++ b/prisma/database/sqlite/schema.prisma @@ -33,5 +33,4 @@ model Device { accessType AccessType @default(PUBLIC) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt - test String? }