-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add boostagram column and use jsonb in metadata
- Loading branch information
1 parent
185895f
commit eb84d63
Showing
12 changed files
with
205 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
db/migrations/202408061737_add_boostagrams_and_use_json.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package migrations | ||
|
||
import ( | ||
_ "embed" | ||
|
||
"github.com/go-gormigrate/gormigrate/v2" | ||
"gorm.io/gorm" | ||
) | ||
|
||
// This migration adds boostagram column to transactions | ||
var _202408061737_add_boostagrams_and_use_json = &gormigrate.Migration{ | ||
ID: "202408061737_add_boostagrams_and_use_json", | ||
Migrate: func(tx *gorm.DB) error { | ||
if err := tx.Exec("ALTER TABLE transactions ADD COLUMN boostagram JSONB").Error; err != nil { | ||
return err | ||
} | ||
|
||
if err := tx.Exec(` | ||
ALTER TABLE transactions ADD COLUMN metadata_temp JSONB; | ||
UPDATE transactions SET metadata_temp = json(metadata); | ||
ALTER TABLE transactions DROP COLUMN metadata; | ||
ALTER TABLE transactions RENAME COLUMN metadata_temp TO metadata; | ||
`).Error; err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
Rollback: func(tx *gorm.DB) error { | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.