Skip to content

Commit f2e24e6

Browse files
committed
remove old staging tables
1 parent dfe1147 commit f2e24e6

File tree

1 file changed

+23
-0
lines changed
  • pkg/postgres/migrations/202508221218_migrateRewardsTables

1 file changed

+23
-0
lines changed

pkg/postgres/migrations/202508221218_migrateRewardsTables/up.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,29 @@ func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
563563
},
564564
}
565565

566+
// Drop staging tables (no data migration needed)
567+
dropStagingTablesQuery := `
568+
SELECT table_name
569+
FROM information_schema.tables
570+
WHERE table_type='BASE TABLE'
571+
AND table_name ~* 'gold_(11|15)_staging_[0-9_]+$'
572+
AND table_schema = 'public'
573+
`
574+
var stagingTables []string
575+
res := grm.Raw(dropStagingTablesQuery).Scan(&stagingTables)
576+
if res.Error != nil {
577+
return fmt.Errorf("failed to find staging tables: %w", res.Error)
578+
}
579+
580+
for _, table := range stagingTables {
581+
dropQuery := fmt.Sprintf("DROP TABLE IF EXISTS %s", table)
582+
dropRes := grm.Exec(dropQuery)
583+
if dropRes.Error != nil {
584+
fmt.Printf("Failed to drop staging table %s: %s\n", table, dropRes.Error)
585+
return dropRes.Error
586+
}
587+
}
588+
566589
_, err := helpers.WrapTxAndCommit(func(tx *gorm.DB) (interface{}, error) {
567590
for _, sm := range subMigrations {
568591
fmt.Printf("Running migration for table: %s\n", sm.NewTableName)

0 commit comments

Comments
 (0)