MCPcopy Create free account
hub / github.com/asternic/wuzapi / createMigrationsTable

Function createMigrationsTable

migrations.go:283–323  ·  view source on GitHub ↗
(db *sqlx.DB)

Source from the content-addressed store, hash-verified

281 if err != nil {
282 return fmt.Errorf("failed to get applied migrations: %w", err)
283 }
284
285 // Apply missing migrations
286 sourceMigrations := make(map[int]string, len(migrations))
287 for _, migration := range migrations {
288 sourceMigrations[migration.ID] = migration.Name
289 if appliedName, ok := applied[migration.ID]; ok && appliedName != migration.Name {
290 log.Warn().
291 Int("migration_id", migration.ID).
292 Str("database_name", appliedName).
293 Str("binary_name", migration.Name).
294 Msg("Database migration ID has a different name in this binary")
295 }
296 }
297 for id, appliedName := range applied {
298 if _, ok := sourceMigrations[id]; !ok {
299 log.Warn().
300 Int("migration_id", id).
301 Str("database_name", appliedName).
302 Msg("Database contains a migration unknown to this binary")
303 }
304 }
305
306 pending := 0
307 for _, migration := range migrations {
308 if _, ok := applied[migration.ID]; !ok {
309 pending++
310 }
311 }
312 log.Info().
313 Str("driver", db.DriverName()).
314 Int("applied", len(applied)).
315 Int("pending", pending).
316 Msg("Database migration status")
317
318 for _, migration := range migrations {
319 if _, ok := applied[migration.ID]; !ok {
320 log.Info().
321 Int("migration_id", migration.ID).
322 Str("migration_name", migration.Name).
323 Msg("Applying database migration")
324 if err := applyMigration(db, migration); err != nil {
325 return fmt.Errorf("failed to apply migration %d: %w", migration.ID, err)
326 }

Callers 1

initializeSchemaFunction · 0.85

Calls 1

GetMethod · 0.80

Tested by

no test coverage detected