MigrateTables relies on the CLI/client to lock before running migration.
(ctx context.Context, messages message.WriteMigrateTables)
| 13 | |
| 14 | // MigrateTables relies on the CLI/client to lock before running migration. |
| 15 | func (c *Client) MigrateTables(ctx context.Context, messages message.WriteMigrateTables) error { |
| 16 | have, err := c.schemaTables(ctx, messages) |
| 17 | if err != nil { |
| 18 | return err |
| 19 | } |
| 20 | |
| 21 | want := normalizedTables(messages) |
| 22 | |
| 23 | if err := checkForced(have, want, messages); err != nil { |
| 24 | return err |
| 25 | } |
| 26 | |
| 27 | for _, want := range want { |
| 28 | c.logger.Info().Str("table", want.Name).Msg("Migrating table") |
| 29 | if len(want.Columns) == 0 { |
| 30 | c.logger.Info().Str("table", want.Name).Msg("Table with no columns, skipping") |
| 31 | continue |
| 32 | } |
| 33 | |
| 34 | have := have.Get(want.Name) |
| 35 | if have == nil { |
| 36 | c.logger.Debug().Str("table", want.Name).Msg("Table doesn't exist, creating") |
| 37 | if err := c.createTable(ctx, want); err != nil { |
| 38 | return err |
| 39 | } |
| 40 | continue |
| 41 | } |
| 42 | |
| 43 | c.logger.Info().Str("table", want.Name).Msg("Table exists, auto-migrating") |
| 44 | if err := c.autoMigrateTable(ctx, have, want); err != nil { |
| 45 | return err |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | return nil |
| 50 | } |
| 51 | |
| 52 | func checkForced(have, want schema.Tables, messages message.WriteMigrateTables) error { |
| 53 | nonAutoMigratableTables := make(map[string][]schema.TableColumnChange) |
nothing calls this directly
no test coverage detected