Enhance entrypoint script for migration handling: Improve error resolution process by adding direct database updates for missing migration files, and refine output messages for clarity during deployment.
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 3m6s

This commit is contained in:
Julien Froidefond
2025-12-15 17:58:40 +01:00
parent d45475fb5a
commit 9b9cc3885a
8 changed files with 78 additions and 56 deletions

View File

@@ -32,7 +32,7 @@ WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
RUN apk add --no-cache python3 make g++
RUN apk add --no-cache python3 make g++ sqlite
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs

File diff suppressed because one or more lines are too long

View File

@@ -1045,8 +1045,7 @@ export const SitePreferencesScalarFieldEnum = {
eventsBackground: 'eventsBackground',
leaderboardBackground: 'leaderboardBackground',
createdAt: 'createdAt',
updatedAt: 'updatedAt',
primaryColor: 'primaryColor'
updatedAt: 'updatedAt'
} as const
export type SitePreferencesScalarFieldEnum = (typeof SitePreferencesScalarFieldEnum)[keyof typeof SitePreferencesScalarFieldEnum]

View File

@@ -154,8 +154,7 @@ export const SitePreferencesScalarFieldEnum = {
eventsBackground: 'eventsBackground',
leaderboardBackground: 'leaderboardBackground',
createdAt: 'createdAt',
updatedAt: 'updatedAt',
primaryColor: 'primaryColor'
updatedAt: 'updatedAt'
} as const
export type SitePreferencesScalarFieldEnum = (typeof SitePreferencesScalarFieldEnum)[keyof typeof SitePreferencesScalarFieldEnum]

View File

@@ -31,7 +31,6 @@ export type SitePreferencesMinAggregateOutputType = {
leaderboardBackground: string | null
createdAt: Date | null
updatedAt: Date | null
primaryColor: string | null
}
export type SitePreferencesMaxAggregateOutputType = {
@@ -41,7 +40,6 @@ export type SitePreferencesMaxAggregateOutputType = {
leaderboardBackground: string | null
createdAt: Date | null
updatedAt: Date | null
primaryColor: string | null
}
export type SitePreferencesCountAggregateOutputType = {
@@ -51,7 +49,6 @@ export type SitePreferencesCountAggregateOutputType = {
leaderboardBackground: number
createdAt: number
updatedAt: number
primaryColor: number
_all: number
}
@@ -63,7 +60,6 @@ export type SitePreferencesMinAggregateInputType = {
leaderboardBackground?: true
createdAt?: true
updatedAt?: true
primaryColor?: true
}
export type SitePreferencesMaxAggregateInputType = {
@@ -73,7 +69,6 @@ export type SitePreferencesMaxAggregateInputType = {
leaderboardBackground?: true
createdAt?: true
updatedAt?: true
primaryColor?: true
}
export type SitePreferencesCountAggregateInputType = {
@@ -83,7 +78,6 @@ export type SitePreferencesCountAggregateInputType = {
leaderboardBackground?: true
createdAt?: true
updatedAt?: true
primaryColor?: true
_all?: true
}
@@ -166,7 +160,6 @@ export type SitePreferencesGroupByOutputType = {
leaderboardBackground: string | null
createdAt: Date
updatedAt: Date
primaryColor: string | null
_count: SitePreferencesCountAggregateOutputType | null
_min: SitePreferencesMinAggregateOutputType | null
_max: SitePreferencesMaxAggregateOutputType | null
@@ -197,7 +190,6 @@ export type SitePreferencesWhereInput = {
leaderboardBackground?: Prisma.StringNullableFilter<"SitePreferences"> | string | null
createdAt?: Prisma.DateTimeFilter<"SitePreferences"> | Date | string
updatedAt?: Prisma.DateTimeFilter<"SitePreferences"> | Date | string
primaryColor?: Prisma.StringNullableFilter<"SitePreferences"> | string | null
}
export type SitePreferencesOrderByWithRelationInput = {
@@ -207,7 +199,6 @@ export type SitePreferencesOrderByWithRelationInput = {
leaderboardBackground?: Prisma.SortOrderInput | Prisma.SortOrder
createdAt?: Prisma.SortOrder
updatedAt?: Prisma.SortOrder
primaryColor?: Prisma.SortOrderInput | Prisma.SortOrder
}
export type SitePreferencesWhereUniqueInput = Prisma.AtLeast<{
@@ -220,7 +211,6 @@ export type SitePreferencesWhereUniqueInput = Prisma.AtLeast<{
leaderboardBackground?: Prisma.StringNullableFilter<"SitePreferences"> | string | null
createdAt?: Prisma.DateTimeFilter<"SitePreferences"> | Date | string
updatedAt?: Prisma.DateTimeFilter<"SitePreferences"> | Date | string
primaryColor?: Prisma.StringNullableFilter<"SitePreferences"> | string | null
}, "id">
export type SitePreferencesOrderByWithAggregationInput = {
@@ -230,7 +220,6 @@ export type SitePreferencesOrderByWithAggregationInput = {
leaderboardBackground?: Prisma.SortOrderInput | Prisma.SortOrder
createdAt?: Prisma.SortOrder
updatedAt?: Prisma.SortOrder
primaryColor?: Prisma.SortOrderInput | Prisma.SortOrder
_count?: Prisma.SitePreferencesCountOrderByAggregateInput
_max?: Prisma.SitePreferencesMaxOrderByAggregateInput
_min?: Prisma.SitePreferencesMinOrderByAggregateInput
@@ -246,7 +235,6 @@ export type SitePreferencesScalarWhereWithAggregatesInput = {
leaderboardBackground?: Prisma.StringNullableWithAggregatesFilter<"SitePreferences"> | string | null
createdAt?: Prisma.DateTimeWithAggregatesFilter<"SitePreferences"> | Date | string
updatedAt?: Prisma.DateTimeWithAggregatesFilter<"SitePreferences"> | Date | string
primaryColor?: Prisma.StringNullableWithAggregatesFilter<"SitePreferences"> | string | null
}
export type SitePreferencesCreateInput = {
@@ -256,7 +244,6 @@ export type SitePreferencesCreateInput = {
leaderboardBackground?: string | null
createdAt?: Date | string
updatedAt?: Date | string
primaryColor?: string | null
}
export type SitePreferencesUncheckedCreateInput = {
@@ -266,7 +253,6 @@ export type SitePreferencesUncheckedCreateInput = {
leaderboardBackground?: string | null
createdAt?: Date | string
updatedAt?: Date | string
primaryColor?: string | null
}
export type SitePreferencesUpdateInput = {
@@ -276,7 +262,6 @@ export type SitePreferencesUpdateInput = {
leaderboardBackground?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
primaryColor?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
}
export type SitePreferencesUncheckedUpdateInput = {
@@ -286,7 +271,6 @@ export type SitePreferencesUncheckedUpdateInput = {
leaderboardBackground?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
primaryColor?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
}
export type SitePreferencesCreateManyInput = {
@@ -296,7 +280,6 @@ export type SitePreferencesCreateManyInput = {
leaderboardBackground?: string | null
createdAt?: Date | string
updatedAt?: Date | string
primaryColor?: string | null
}
export type SitePreferencesUpdateManyMutationInput = {
@@ -306,7 +289,6 @@ export type SitePreferencesUpdateManyMutationInput = {
leaderboardBackground?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
primaryColor?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
}
export type SitePreferencesUncheckedUpdateManyInput = {
@@ -316,7 +298,6 @@ export type SitePreferencesUncheckedUpdateManyInput = {
leaderboardBackground?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
primaryColor?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
}
export type SitePreferencesCountOrderByAggregateInput = {
@@ -326,7 +307,6 @@ export type SitePreferencesCountOrderByAggregateInput = {
leaderboardBackground?: Prisma.SortOrder
createdAt?: Prisma.SortOrder
updatedAt?: Prisma.SortOrder
primaryColor?: Prisma.SortOrder
}
export type SitePreferencesMaxOrderByAggregateInput = {
@@ -336,7 +316,6 @@ export type SitePreferencesMaxOrderByAggregateInput = {
leaderboardBackground?: Prisma.SortOrder
createdAt?: Prisma.SortOrder
updatedAt?: Prisma.SortOrder
primaryColor?: Prisma.SortOrder
}
export type SitePreferencesMinOrderByAggregateInput = {
@@ -346,7 +325,6 @@ export type SitePreferencesMinOrderByAggregateInput = {
leaderboardBackground?: Prisma.SortOrder
createdAt?: Prisma.SortOrder
updatedAt?: Prisma.SortOrder
primaryColor?: Prisma.SortOrder
}
@@ -358,7 +336,6 @@ export type SitePreferencesSelect<ExtArgs extends runtime.Types.Extensions.Inter
leaderboardBackground?: boolean
createdAt?: boolean
updatedAt?: boolean
primaryColor?: boolean
}, ExtArgs["result"]["sitePreferences"]>
export type SitePreferencesSelectCreateManyAndReturn<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetSelect<{
@@ -368,7 +345,6 @@ export type SitePreferencesSelectCreateManyAndReturn<ExtArgs extends runtime.Typ
leaderboardBackground?: boolean
createdAt?: boolean
updatedAt?: boolean
primaryColor?: boolean
}, ExtArgs["result"]["sitePreferences"]>
export type SitePreferencesSelectUpdateManyAndReturn<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetSelect<{
@@ -378,7 +354,6 @@ export type SitePreferencesSelectUpdateManyAndReturn<ExtArgs extends runtime.Typ
leaderboardBackground?: boolean
createdAt?: boolean
updatedAt?: boolean
primaryColor?: boolean
}, ExtArgs["result"]["sitePreferences"]>
export type SitePreferencesSelectScalar = {
@@ -388,10 +363,9 @@ export type SitePreferencesSelectScalar = {
leaderboardBackground?: boolean
createdAt?: boolean
updatedAt?: boolean
primaryColor?: boolean
}
export type SitePreferencesOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "homeBackground" | "eventsBackground" | "leaderboardBackground" | "createdAt" | "updatedAt" | "primaryColor", ExtArgs["result"]["sitePreferences"]>
export type SitePreferencesOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "homeBackground" | "eventsBackground" | "leaderboardBackground" | "createdAt" | "updatedAt", ExtArgs["result"]["sitePreferences"]>
export type $SitePreferencesPayload<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
name: "SitePreferences"
@@ -403,7 +377,6 @@ export type $SitePreferencesPayload<ExtArgs extends runtime.Types.Extensions.Int
leaderboardBackground: string | null
createdAt: Date
updatedAt: Date
primaryColor: string | null
}, ExtArgs["result"]["sitePreferences"]>
composites: {}
}
@@ -833,7 +806,6 @@ export interface SitePreferencesFieldRefs {
readonly leaderboardBackground: Prisma.FieldRef<"SitePreferences", 'String'>
readonly createdAt: Prisma.FieldRef<"SitePreferences", 'DateTime'>
readonly updatedAt: Prisma.FieldRef<"SitePreferences", 'DateTime'>
readonly primaryColor: Prisma.FieldRef<"SitePreferences", 'String'>
}

View File

@@ -0,0 +1,22 @@
-- AlterTable
-- SQLite doesn't support DROP COLUMN directly, so we need to recreate the table
CREATE TABLE "SitePreferences_new" (
"id" TEXT NOT NULL PRIMARY KEY,
"homeBackground" TEXT,
"eventsBackground" TEXT,
"leaderboardBackground" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
-- Copy data without primaryColor column
INSERT INTO "SitePreferences_new" ("id", "homeBackground", "eventsBackground", "leaderboardBackground", "createdAt", "updatedAt")
SELECT "id", "homeBackground", "eventsBackground", "leaderboardBackground", "createdAt", "updatedAt"
FROM "SitePreferences";
-- Drop old table
DROP TABLE "SitePreferences";
-- Rename new table
ALTER TABLE "SitePreferences_new" RENAME TO "SitePreferences";

View File

@@ -101,7 +101,6 @@ model SitePreferences {
leaderboardBackground String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
primaryColor String? @default("#0be4cc")
}
enum Role {

View File

@@ -45,34 +45,65 @@ deploy_migrations() {
echo "Resolving failed migration: $MIGRATION_NAME"
# Try to resolve as applied (migration might have partially succeeded)
# First, try the standard Prisma resolve command
RESOLVE_OUTPUT=$(pnpm dlx prisma migrate resolve --applied "$MIGRATION_NAME" 2>&1)
RESOLVE_EXIT=$?
echo "$RESOLVE_OUTPUT"
if [ $RESOLVE_EXIT -eq 0 ]; then
echo "Migration resolved successfully, retrying deploy..."
# Retry migration deploy
if pnpm dlx prisma migrate deploy 2>&1; then
echo "Migrations deployed successfully after resolution"
return 0
else
echo "Migration deploy still failed after resolution, but continuing..."
return 0
fi
else
# Check if migration is already marked as applied
if echo "$RESOLVE_OUTPUT" | grep -q "already recorded as applied"; then
echo "Migration is already marked as applied, retrying deploy..."
pnpm dlx prisma migrate deploy 2>&1 || true
return 0
# If Prisma resolve fails (e.g., migration files not found), resolve directly in database
if [ $RESOLVE_EXIT -ne 0 ]; then
if echo "$RESOLVE_OUTPUT" | grep -q "P3017\|could not be found"; then
echo "Migration files not found, resolving directly in database..."
# Use sqlite3 to mark migration as applied directly in _prisma_migrations table
# Check if sqlite3 is available
if command -v sqlite3 >/dev/null 2>&1; then
# Extract database path from DATABASE_URL (format: file:/app/data/dev.db)
DB_PATH=$(echo "$DATABASE_URL" | sed 's|file:||')
if [ -z "$DB_PATH" ] || [ "$DB_PATH" = "$DATABASE_URL" ]; then
DB_PATH="/app/data/dev.db"
fi
# Ensure database file exists
if [ ! -f "$DB_PATH" ]; then
echo "Database file not found at $DB_PATH"
else
echo "Updating migration status in database: $DB_PATH"
# Get current timestamp in milliseconds
TIMESTAMP=$(date +%s)000
# Update the migration record
sqlite3 "$DB_PATH" "UPDATE _prisma_migrations SET finished_at = $TIMESTAMP, rolled_back_at = NULL WHERE migration_name = '$MIGRATION_NAME' AND finished_at IS NULL;" 2>&1
if [ $? -eq 0 ]; then
echo "Migration marked as applied in database"
# Verify the update
RESULT=$(sqlite3 "$DB_PATH" "SELECT migration_name, finished_at FROM _prisma_migrations WHERE migration_name = '$MIGRATION_NAME';" 2>&1)
echo "Migration status: $RESULT"
else
echo "Failed to update database directly"
fi
fi
else
echo "sqlite3 not available, cannot resolve directly in database"
echo "Install sqlite3 in Dockerfile: RUN apk add --no-cache sqlite"
fi
elif echo "$RESOLVE_OUTPUT" | grep -q "already recorded as applied"; then
echo "Migration is already marked as applied"
else
echo "Failed to resolve migration: $RESOLVE_OUTPUT"
echo "Continuing anyway - app might still work if migration was partially applied"
return 0
fi
fi
# Retry migration deploy after resolution attempt
echo "Retrying migration deploy..."
if pnpm dlx prisma migrate deploy 2>&1; then
echo "Migrations deployed successfully after resolution"
return 0
else
echo "Migration deploy still failed after resolution, but continuing..."
return 0
fi
}
# Deploy migrations (don't fail if it errors - app might still work)