github.com/deso-protocol/core@v1.2.9/migrate/20210917204532_nft_transfer_and_burn_update.go (about) 1 package migrate 2 3 import ( 4 "github.com/go-pg/pg/v10/orm" 5 migrations "github.com/robinjoseph08/go-pg-migrations/v3" 6 ) 7 8 func init() { 9 up := func(db orm.DB) error { 10 _, err := db.Exec(` 11 CREATE TABLE pg_metadata_nft_transfer ( 12 transaction_hash BYTEA PRIMARY KEY, 13 nft_post_hash BYTEA NOT NULL, 14 serial_number BIGINT NOT NULL, 15 receiver_public_key BYTEA NOT NULL, 16 unlockable_text BYTEA NOT NULL 17 ); 18 `) 19 if err != nil { 20 return err 21 } 22 23 _, err = db.Exec(` 24 CREATE TABLE pg_metadata_accept_nft_transfer ( 25 transaction_hash BYTEA PRIMARY KEY, 26 nft_post_hash BYTEA NOT NULL, 27 serial_number BIGINT NOT NULL 28 ); 29 `) 30 if err != nil { 31 return err 32 } 33 34 _, err = db.Exec(` 35 CREATE TABLE pg_metadata_burn_nft ( 36 transaction_hash BYTEA PRIMARY KEY, 37 nft_post_hash BYTEA NOT NULL, 38 serial_number BIGINT NOT NULL 39 ); 40 `) 41 if err != nil { 42 return err 43 } 44 45 _, err = db.Exec(` 46 ALTER TABLE IF EXISTS pg_posts 47 ADD num_nft_copies_for_sale BIGINT, 48 ADD num_nft_copies_burned BIGINT 49 ; 50 ALTER TABLE IF EXISTS pg_nfts 51 ADD is_pending BOOL 52 ; 53 `) 54 55 return nil 56 } 57 58 down := func(db orm.DB) error { 59 _, err := db.Exec(` 60 DROP TABLE pg_metadata_nft_transfer; 61 DROP TABLE pg_metadata_accept_nft_transfer; 62 DROP TABLE pg_metadata_burn_nft; 63 ALTER TABLE IF EXISTS pg_posts 64 DROP COLUMN IF EXISTS num_nft_copies_for_sale, 65 DROP COLUMN IF EXISTS num_nft_copies_burned 66 ; 67 ALTER TABLE IF EXISTS pg_nfts 68 DROP COLUMN IF EXISTS is_pending 69 ; 70 `) 71 if err != nil { 72 return err 73 } 74 75 return nil 76 } 77 78 opts := migrations.MigrationOptions{} 79 80 migrations.Register("20210917204532_nft_transfer_and_burn_update", up, down, opts) 81 }