fix: skip migrations during build phase to prevent 'table already exists' errors
This commit is contained in:
parent
ecb23855b5
commit
bbaf330020
4 changed files with 40 additions and 9 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -9,3 +9,4 @@ build
|
|||
data/
|
||||
__pycache__/
|
||||
mlruns
|
||||
AI-grep/
|
||||
|
|
|
|||
|
|
@ -325,7 +325,7 @@ curl -X POST http://localhost:8001/predict \
|
|||
The easiest way to deploy is with docker-compose:
|
||||
|
||||
```bash
|
||||
docker-compose up --build
|
||||
docker compose up --build
|
||||
```
|
||||
|
||||
This will:
|
||||
|
|
@ -497,6 +497,23 @@ docker-compose up -d
|
|||
docker-compose logs -f --tail=100
|
||||
```
|
||||
|
||||
**ML service healthcheck failing:**
|
||||
|
||||
If the candle-annotator service fails to start with error "dependency failed to start: container candle_annotator-ml-service-1 is unhealthy", this is because the ml-service healthcheck requires `curl` to be installed in the container. This was fixed in commit `ecb2385` by adding curl to the ml-service Dockerfile.
|
||||
|
||||
If you encounter this issue:
|
||||
1. Rebuild the ml-service: `docker compose build ml-service`
|
||||
2. Restart services: `docker compose up -d`
|
||||
|
||||
**Migration errors during build:**
|
||||
|
||||
If you see Drizzle migration errors like "table `annotations` already exists" during the Docker build process, this means the database file from a previous build is being included. This was fixed in commit by skipping migrations during the build phase. The migrations now only run at runtime.
|
||||
|
||||
If you encounter this issue:
|
||||
1. Ensure `data/` is in `.dockerignore`
|
||||
2. Rebuild: `docker compose build --no-cache candle-annotator`
|
||||
3. Restart: `docker compose up -d`
|
||||
|
||||
### Update Procedure
|
||||
|
||||
To update the application:
|
||||
|
|
|
|||
2
next-env.d.ts
vendored
2
next-env.d.ts
vendored
|
|
@ -1,6 +1,6 @@
|
|||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
import "./.next/dev/types/routes.d.ts";
|
||||
import "./.next/types/routes.d.ts";
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||
|
|
|
|||
|
|
@ -15,11 +15,24 @@ const dbPath = path.join(dataDir, 'candles.db');
|
|||
const sqlite = new Database(dbPath);
|
||||
export const db = drizzle(sqlite, { schema });
|
||||
|
||||
// Run migrations on startup
|
||||
try {
|
||||
migrate(db, { migrationsFolder: path.join(process.cwd(), 'drizzle') });
|
||||
console.log('✅ Database migrations completed');
|
||||
} catch (error) {
|
||||
console.error('❌ Migration failed:', error);
|
||||
throw error;
|
||||
// Run migrations only in runtime (not during build)
|
||||
// Check if we're in build mode by looking for the NEXT_PHASE environment variable
|
||||
const isBuildTime = process.env.NEXT_PHASE === 'phase-production-build' || process.env.NEXT_PHASE === 'phase-development-build';
|
||||
|
||||
if (!isBuildTime) {
|
||||
try {
|
||||
migrate(db, { migrationsFolder: path.join(process.cwd(), 'drizzle') });
|
||||
console.log('✅ Database migrations completed');
|
||||
} catch (error) {
|
||||
// Check if error is about table already existing
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
if (errorMessage.includes('already exists')) {
|
||||
console.log('⚠️ Database tables already exist, skipping migrations');
|
||||
} else {
|
||||
console.error('❌ Migration failed:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log('ℹ️ Skipping migrations during build phase');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue