fix and update
This commit is contained in:
@@ -1,13 +1,22 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
echo "[sso-core] Применение схемы БД (Prisma)..."
|
||||
echo "[sso-core] Применение схемы БД (Prisma migrate deploy → db push)..."
|
||||
attempt=0
|
||||
max_attempts=30
|
||||
|
||||
apply_prisma_schema() {
|
||||
if npm --workspace @lendry/sso-core run prisma:migrate-deploy; then
|
||||
echo "[sso-core] Миграции Prisma применены (migrate deploy)"
|
||||
return 0
|
||||
fi
|
||||
echo "[sso-core] migrate deploy не выполнен — пробуем db push..."
|
||||
npm --workspace @lendry/sso-core run prisma:push
|
||||
}
|
||||
|
||||
while [ "$attempt" -lt "$max_attempts" ]; do
|
||||
attempt=$((attempt + 1))
|
||||
if npm --workspace @lendry/sso-core run prisma:push; then
|
||||
if apply_prisma_schema; then
|
||||
echo "[sso-core] Схема БД синхронизирована"
|
||||
break
|
||||
fi
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"prisma:format": "prisma format --schema prisma/schema.prisma",
|
||||
"prisma:generate": "prisma generate --schema prisma/schema.prisma",
|
||||
"prisma:push": "prisma db push --schema prisma/schema.prisma --accept-data-loss",
|
||||
"prisma:migrate-deploy": "prisma migrate deploy --schema prisma/schema.prisma",
|
||||
"proto:generate": "node scripts/generate-proto-types.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE IF NOT EXISTS "UserActivityLog" (
|
||||
"id" TEXT NOT NULL,
|
||||
"userId" TEXT NOT NULL,
|
||||
"action" TEXT NOT NULL,
|
||||
"title" TEXT NOT NULL,
|
||||
"detail" TEXT,
|
||||
"entityType" TEXT,
|
||||
"entityId" TEXT,
|
||||
"ipAddress" TEXT,
|
||||
"userAgent" TEXT,
|
||||
"actorId" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "UserActivityLog_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX IF NOT EXISTS "UserActivityLog_userId_createdAt_idx" ON "UserActivityLog"("userId", "createdAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX IF NOT EXISTS "UserActivityLog_userId_action_idx" ON "UserActivityLog"("userId", "action");
|
||||
|
||||
-- AddForeignKey
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint WHERE conname = 'UserActivityLog_userId_fkey'
|
||||
) THEN
|
||||
ALTER TABLE "UserActivityLog"
|
||||
ADD CONSTRAINT "UserActivityLog_userId_fkey"
|
||||
FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
END IF;
|
||||
END $$;
|
||||
3
apps/sso-core/prisma/migrations/migration_lock.toml
Normal file
3
apps/sso-core/prisma/migrations/migration_lock.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (i.e. Git)
|
||||
provider = "postgresql"
|
||||
Reference in New Issue
Block a user