migrate applies idempotent, additive schema changes to databases created by older versions. ADD COLUMN on an existing column returns a "duplicate column" error which we treat as already-applied.
(ctx context.Context, db *sql.DB)
| 63 | // older versions. ADD COLUMN on an existing column returns a "duplicate column" |
| 64 | // error which we treat as already-applied. |
| 65 | func migrate(ctx context.Context, db *sql.DB) error { |
| 66 | for _, stmt := range []string{ |
| 67 | `ALTER TABLE providers ADD COLUMN api_key TEXT NOT NULL DEFAULT ''`, |
| 68 | } { |
| 69 | if _, err := db.ExecContext(ctx, stmt); err != nil { |
| 70 | if strings.Contains(err.Error(), "duplicate column name") { |
| 71 | continue |
| 72 | } |
| 73 | return err |
| 74 | } |
| 75 | } |
| 76 | return nil |
| 77 | } |
| 78 | |
| 79 | // ImportProvidersJSON is a no-op. Providers were historically migrated from a |
| 80 | // legacy providers.json file into the SQLite store. That migration is complete |