github.com/deso-protocol/core@v1.2.9/migrate/20210907001756_derived_keys_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_derived_keys ( 12 transaction_hash BYTEA PRIMARY KEY, 13 derived_public_key BYTEA NOT NULL, 14 expiration_block BIGINT NOT NULL, 15 operation_type SMALLINT NOT NULL, 16 access_signature BYTEA NOT NULL 17 ); 18 `) 19 if err != nil { 20 return err 21 } 22 23 _, err = db.Exec(` 24 CREATE TABLE pg_derived_keys ( 25 owner_public_key BYTEA NOT NULL, 26 derived_public_key BYTEA NOT NULL, 27 expiration_block BIGINT NOT NULL, 28 operation_type SMALLINT NOT NULL, 29 30 PRIMARY KEY (owner_public_key, derived_public_key) 31 ); 32 `) 33 if err != nil { 34 return err 35 } 36 37 return nil 38 } 39 40 down := func(db orm.DB) error { 41 _, err := db.Exec(` 42 DROP TABLE pg_metadata_derived_keys; 43 DROP TABLE pg_derived_keys; 44 `) 45 if err != nil { 46 return err 47 } 48 49 return nil 50 } 51 52 opts := migrations.MigrationOptions{} 53 54 migrations.Register("20210907001756_derived_keys_update", up, down, opts) 55 }