## Motivations A lot of self hosters hands up using the `yarn database:migrated:prod` either manually or through AI assisted debug while they try to upgrade an instance while their workspace is still blocked in a previous one Leading to their whole database permanent corruption ## What happened Replaced the direct call the the typeorm cli to a command calling it programmatically, adding a layer of security in case a workspace seems to be blocked in a previous version than the one just before the one being installed ( e.g 1.0 when you try to upgrade from 1.1 to 1.2 ) For our cloud we still need a way to bypass this security explaining the -f flag ## Remark Centralized this logic and refactored creating new services `WorkspaceVersionService` and `CoreEngineVersionService` that will become useful for the upcoming upgrade refactor Related to https://github.com/twentyhq/twenty-infra/pull/529
45 lines
1.2 KiB
Bash
Executable File
45 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
|
|
setup_and_migrate_db() {
|
|
if [ "${DISABLE_DB_MIGRATIONS}" = "true" ]; then
|
|
echo "Database setup and migrations are disabled, skipping..."
|
|
return
|
|
fi
|
|
|
|
echo "Running database setup and migrations..."
|
|
|
|
# Run setup and migration scripts
|
|
has_schema=$(psql -tAc "SELECT EXISTS (SELECT 1 FROM information_schema.schemata WHERE schema_name = 'core')" ${PG_DATABASE_URL})
|
|
if [ "$has_schema" = "f" ]; then
|
|
echo "Database appears to be empty, running migrations."
|
|
yarn database:init:prod
|
|
fi
|
|
|
|
yarn command:prod cache:flush
|
|
yarn command:prod upgrade
|
|
yarn command:prod cache:flush
|
|
|
|
echo "Successfully migrated DB!"
|
|
}
|
|
|
|
register_background_jobs() {
|
|
if [ "${DISABLE_CRON_JOBS_REGISTRATION}" = "true" ]; then
|
|
echo "Cron job registration is disabled, skipping..."
|
|
return
|
|
fi
|
|
|
|
echo "Registering background sync jobs..."
|
|
if yarn command:prod cron:register:all; then
|
|
echo "Successfully registered all background sync jobs!"
|
|
else
|
|
echo "Warning: Failed to register background jobs, but continuing startup..."
|
|
fi
|
|
}
|
|
|
|
setup_and_migrate_db
|
|
register_background_jobs
|
|
|
|
# Continue with the original Docker command
|
|
exec "$@"
|