Commit a7d62ea
committed
fix(db): create base schema before running migrations
Migrations ran before `_Base.metadata.create_all()`, so migration 3->4
(`ALTER TABLE user_mappings ADD COLUMN avatar_url`) failed on a fresh or
partially-initialized database where the ORM-model tables did not yet
exist — no migration creates the core tables (user_mappings,
message_mappings, user_bindings, binding_codes); they are defined only
by the ORM models, while migrations 0->3 touch only the forward_* tables.
Move `create_all` ahead of `_run_migrations` in `MessageDB.__init__` and
drop the migration call from `_create_engine_from_config`. Init is now
self-healing: create_all builds the current schema (recreating any missing
tables), then idempotent migrations apply incremental ALTERs.
Fixes "Startup aborted: database initialization failed".1 parent cb2ddbd commit a7d62ea
1 file changed
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
122 | 127 | | |
| 128 | + | |
123 | 129 | | |
124 | 130 | | |
125 | 131 | | |
| |||
180 | 186 | | |
181 | 187 | | |
182 | 188 | | |
183 | | - | |
184 | | - | |
185 | 189 | | |
186 | 190 | | |
187 | 191 | | |
| |||
0 commit comments