Migrate
Migrate applies all unapplied SQL migration files from the provided fs.FS. Migration files are expected to be located under "sql/" and follow the naming convention "NNNN_description.sql". Files ending with "_down.sql" are skipped. Migrations are applied in lexicographic order, each within its own transaction. The prefix parameter namespaces versions in the shared schema_migrations table so that multiple services sharing the same database do not collide (e.g. prefix "runs" records version "runs/001_init_schema").
def Migrate(
ctx: context.Context,
db: *sqlx.DB,
prefix: string,
migrations: fs.FS
) - > error
Migrate applies all unapplied SQL migration files from the provided fs.FS. Migration files are expected to be located under "sql/" and follow the naming convention "NNNN_description.sql". Files ending with "_down.sql" are skipped. Migrations are applied in lexicographic order, each within its own transaction. The prefix parameter namespaces versions in the shared schema_migrations table so that multiple services sharing the same database do not collide (e.g. prefix "runs" records version "runs/001_init_schema").
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | The context for the operation, allowing for cancellation and timeouts. |
| db | *sqlx.DB | The database connection pool to apply migrations to. |
| prefix | string | A string prefix used to namespace migration versions in the schema_migrations table, preventing collisions between multiple services sharing the same database. |
| migrations | fs.FS | The file system containing the SQL migration files, expected to be under the "sql/" directory. |
Returns
| Type | Description |
|---|---|
error | An error if any step of the migration process fails, otherwise nil. |