Skip to content

Commit

Permalink
Fix postgres down migrations. (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfoley8 authored Mar 18, 2022
1 parent 18e2efa commit 350a976
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion migrate/20220106162320_create_dao_coin_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func init() {
down := func(db orm.DB) error {
_, err := db.Exec(`
DROP TABLE pg_metadata_dao_coins;
DROP TABLE pg_metadata_dao_coin_transfer;
DROP TABLE pg_metadata_dao_coin_transfers;
DROP TABLE pg_dao_coin_balances;
ALTER TABLE pg_profiles
DROP COLUMN minting_disabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@ func init() {
down := func(db orm.DB) error {
_, err := db.Exec(`
ALTER TABLE pg_nfts
DROP COLUMN additional_nft_royalties_to_coins_basis_points,
DROP COLUMN additional_nft_royalties_to_creators_basis_points;
ALTER TABLE pg_posts
DROP COLUMN is_buy_now,
DROP COLUMN buy_now_price_nanos;
ALTER TABLE pg_posts
DROP COLUMN additional_nft_royalties_to_coins_basis_points,
DROP COLUMN additional_nft_royalties_to_creators_basis_points;
ALTER TABLE pg_dao_coin_balances
ALTER COLUMN balance_nanos TYPE BIGINT USING lpad(balance_nanos, 16, '0')::bit(64)::bigint;
ALTER COLUMN balance_nanos TYPE BIGINT USING ('x' || lpad(replace(balance_nanos, '0x', ''), 16, '0'))::bit(64)::bigint;
ALTER TABLE pg_metadata_dao_coin_transfers
ALTER COLUMN dao_coin_to_transfer_nanos TYPE BIGINT USING lpad(dao_coin_to_transfer_nanos, 16, '0')::bit(64)::bigint;
ALTER COLUMN dao_coin_to_transfer_nanos TYPE BIGINT USING ('x' || lpad(replace(dao_coin_to_transfer_nanos, '0x', ''), 16, '0'))::bit(64)::bigint;
ALTER TABLE pg_metadata_dao_coins
ALTER COLUMN coins_to_mint_nanos TYPE BIGINT USING lpad(coins_to_mint_nanos, 16, '0')::bit(64)::bigint,
ALTER COLUMN coins_to_burn_nanos TYPE BIGINT USING lpad(coins_to_burn_nanos, 16, '0')::bit(64)::bigint;
ALTER COLUMN coins_to_mint_nanos TYPE BIGINT USING ('x' || lpad(replace(coins_to_mint_nanos, '0x', ''), 16, '0'))::bit(64)::bigint,
ALTER COLUMN coins_to_burn_nanos TYPE BIGINT USING ('x' || lpad(replace(coins_to_burn_nanos, '0x', ''), 16, '0'))::bit(64)::bigint;
ALTER TABLE pg_profiles
ALTER COLUMN dao_coin_coins_in_circulation_nanos TYPE BIGINT USING lpad(dao_coin_coins_in_circulation_nanos, 16, '0')::bit(64)::bigint;
ALTER COLUMN dao_coin_coins_in_circulation_nanos TYPE BIGINT USING ('x' || lpad(replace(dao_coin_coins_in_circulation_nanos, '0x', ''), 16, '0'))::bit(64)::bigint;
`)
return err
}
Expand Down
3 changes: 0 additions & 3 deletions migrate/init.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package migrate

import "github.com/golang/glog"

// LoadMigrations forces Go to call init() on all the files in this package.
// The library we use for migrations, go-pg-migrations, needs to be refactored to
// not use this terrible loading pattern. It's hard to test, can cause weird side effects,
// and is the reason we need this weird LoadMigrations method
func LoadMigrations() {
glog.Info("Loading all migrations...")
}

0 comments on commit 350a976

Please sign in to comment.