-
Notifications
You must be signed in to change notification settings - Fork 0
DB Push
gco db push compares your .gcorm schema with a live database and executes
the generated SQL needed to align the database with the schema.
db push supports:
- PostgreSQL
- MySQL
- SQLite
The provider is read from the schema datasource:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
gco db push --schema schemaUse an explicit URL:
gco db push --schema schema --url "$DATABASE_URL"Use a config file:
gco db push --config gco.config.yamlFor production binaries that embed .gcorm files and call dbpush.Push
directly, see Embedded DB Push.
GCORM resolves the database URL in this order:
--url <connection-url>datasource url = env("NAME")datasource url = "literal-url"
If the schema uses env("DATABASE_URL"), the environment variable must be set
before running db push.
db push:
- Discovers and compiles schema files.
- Resolves the database URL.
- Connects to the database.
- Introspects the current database schema.
- Computes a diff.
- Refuses destructive changes unless
--forceis provided. - Executes supported SQL statements in a transaction.
If no changes are detected, the command exits without executing SQL.
Examples of destructive changes include dropping tables, dropping columns, and
some type changes. Without --force, GCORM refuses to apply them:
gco db push --schema schemaTo allow destructive changes:
gco db push --schema schema --forceOnly use --force after reviewing the diff impact and backing up important
data.
Good fit:
- Local development.
- Test databases.
- Disposable preview databases.
- Small internal tools where direct schema sync is acceptable.
- Explicit production migrator jobs that embed trusted
.gcormfiles and use Embedded DB Push.
Use migrations instead when:
- You need a reviewed SQL history.
- Production policy requires reviewed SQL files.
- Multiple application versions may run during deploys.
- Data backfills or custom SQL are required.
PostgreSQL:
- Supports schema namespaces.
- Uses
$1,$2, ... placeholders in generated runtime queries. - Connection URLs often need
sslmode=disablefor local development.
MySQL:
- Use DSNs with
parseTime=trueforDateTimefields. - Uses
?placeholders.
SQLite:
- File URLs and plain file paths are supported.
- Some schema changes require table rebuild patterns.
- Transaction behavior depends on the SQLite driver and connection settings.
db push applies generated SQL. It is not a substitute for hand-reviewed
production migration planning. If generated SQL includes an unsupported pattern,
the command reports an error instead of executing that SQL.