You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Drop automatic migration relocation for a documented manual step
Remove the auto relocation + checksum re-stamp from setup() and the
public relocate_legacy_migrations_table / reconcile_migration_checksums helpers.
setup() now just runs migrations.
Docs now cover the two failure modes (function-already-exists on a blind
upgrade, and the empty apalis._sqlx_migrations that then blocks the
ALTER TABLE).
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1-4Lines changed: 1 addition & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,10 +6,7 @@
6
6
-`generate_ulid` is now `apalis.generate_ulid` and no longer depends on `pgcrypto` — its random bytes come from core `gen_random_uuid()`. The sole caller (`apalis.push_job`) is repointed and the `public.generate_ulid` copy is dropped (via a new forward migration; existing migrations are not rewritten).
7
7
- The sqlx migrations table is tracked in `apalis._sqlx_migrations` instead of `public._sqlx_migrations` (configured in a new `sqlx.toml`). This also isolates apalis's migration history from a user's own sqlx migrations on the same database, which previously collided over the shared default table name.
8
8
- bump: upgrade `sqlx` 0.8 → 0.9 (required for `sqlx.toml`); remap the runtime/TLS cargo features since 0.9 removed the combined `runtime-*-tls` flags.
9
-
-**Upgrade is automatic when you use `PostgresStorage::setup()`.** On first run it relocates an existing `public._sqlx_migrations` into the `apalis` schema and re-stamps checksums before running migrations, so existing deployments migrate with no manual steps and nothing is re-run. (The only edited migration is the first one — `CREATE SCHEMA` → `CREATE SCHEMA IF NOT EXISTS`, needed so the `apalis` schema can be created before the tracking table on fresh installs — whose checksum is healed automatically.)
10
-
-**If you apply migrations yourself**, `setup()` doesn't run, so on an existing database you perform the one-time transition before upgrading (no-op on fresh databases). The relocation and checksum re-stamp are exposed as `PostgresStorage::relocate_legacy_migrations_table` and `PostgresStorage::reconcile_migration_checksums`:
11
-
- sqlx CLI, or you copied the migration files into your own project: run the relocation + re-stamp SQL documented under "Upgrading to 1.0" in the README.
12
-
- you merge `PostgresStorage::migrations()` into your own `Migrator`: your migrator keeps its own tracking table, so don't relocate — just call `reconcile_migration_checksums(&pool, "<your table>")` before running it to heal the one edited migration's checksum.
9
+
-**Existing databases need a one-time manual step before upgrading** (fresh databases need nothing — `sqlx.toml` creates the `apalis` schema and tracking table). Move the migration history into the `apalis` schema and re-stamp the one edited migration's checksum — the first migration changed `CREATE SCHEMA` → `CREATE SCHEMA IF NOT EXISTS` so the `apalis` schema can be created before the tracking table on fresh installs. See "Upgrading to 1.0" in the README for the SQL; it applies to every apply path (`setup()`, sqlx-cli, copied migrations, or a merged `Migrator`).
13
10
- note: `pgcrypto` is no longer used by apalis but is left where an earlier version installed it (usually `public`). If nothing else needs it, you can `DROP EXTENSION pgcrypto;`.
Copy file name to clipboardExpand all lines: README.md
+10-16Lines changed: 10 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -227,39 +227,33 @@ Track your jobs using [apalis-board](https://github.com/apalis-dev/apalis-board)
227
227
- The sqlx migrations table is now tracked in `apalis._sqlx_migrations` (configured in `sqlx.toml`) instead of `public._sqlx_migrations`. This also keeps apalis's migration history from colliding with your own sqlx migrations on the same database.
228
228
-`generate_ulid()` is now `apalis.generate_ulid()` and no longer depends on the `pgcrypto` extension — its random bytes come from core `gen_random_uuid()`. The `public.generate_ulid()` copy is dropped.
229
229
230
-
### If you use `PostgresStorage::setup()`
230
+
### Existing databases: one-time manual step
231
231
232
-
Nothing to do. On the next start, `setup()` relocates an existing `public._sqlx_migrations` into the `apalis` schema and re-stamps checksums before running migrations, so the upgrade is automatic and nothing is re-run.
233
-
234
-
### If you apply migrations yourself (sqlx-cli, or you copied the migration files into your own project)
235
-
236
-
`setup()` is what performs the relocation, so paths that bypass it need one manual, one-time step **before** running the 1.0 migrations against an existing database:
232
+
This applies to **every** way of applying migrations — `PostgresStorage::setup()`, sqlx-cli, copied migration files, or a merged `Migrator`. Run this **once per database, before upgrading**:
237
233
238
234
```sql
239
235
-- Move apalis's existing migration history into the apalis schema.
-- The first migration gained `IF NOT EXISTS` (so the apalis schema can be
243
239
-- created before the tracking table on fresh installs). Re-stamp its checksum
244
-
-- so sqlx doesn't reject it as modified:
240
+
-- so the migrator doesn't reject it as modified:
245
241
UPDATEapalis._sqlx_migrations
246
242
SET checksum = decode('d0839c6f57a379769dc27ccd581feb3d2709239c8f138e05271c9e3c760c4517a78a4d8912ab3d63b074b28d15ec74e9', 'hex')
247
243
WHERE version =20220530084123;
248
244
```
249
245
250
-
Fresh databases need none of this — `sqlx.toml` creates the `apalis` schema and tracking table for you.
246
+
Run it **before** upgrading. If you upgrade first without it, the migrator re-runs the first migration against your existing objects and fails with e.g. `function "notify_new_jobs" already exists`. If you've already hit that failure, an empty `apalis._sqlx_migrations` may have been created, which makes the `ALTER TABLE` above fail because the name is taken — drop it first:
251
247
252
-
### If you merge `PostgresStorage::migrations()` into your own `Migrator`
248
+
```sql
249
+
DROPTABLEapalis._sqlx_migrations;
250
+
```
253
251
254
-
Your migrator owns its own tracking table, so it doesn't move to `apalis` and you don't run the relocation above. You only need to heal the one edited migration's checksum so your migrator doesn't reject it as modified. On an existing database, before running your migrator:
252
+
then run the two statements above.
255
253
256
-
```rust
257
-
// `_sqlx_migrations` (or whatever table your Migrator uses)
If you maintain your **own**`Migrator` (merging in `PostgresStorage::migrations()`), your tracking table stays where it is — skip the `ALTER TABLE` and run only the `UPDATE`, targeting your table name.
261
255
262
-
It is a no-op on fresh databases.
256
+
Fresh databases need none of this — `sqlx.toml` creates the `apalis` schema and tracking table for you.
0 commit comments