github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/internal/datastore/postgres/migrations/zz_migration.0009_caveat.go (about) 1 package migrations 2 3 import ( 4 "context" 5 6 "github.com/jackc/pgx/v5" 7 ) 8 9 var caveatStatements = []string{ 10 `CREATE TABLE caveat ( 11 name VARCHAR NOT NULL, 12 definition BYTEA NOT NULL, 13 created_transaction BIGINT NOT NULL, 14 deleted_transaction BIGINT NOT NULL DEFAULT '9223372036854775807', 15 CONSTRAINT pk_caveat_v1 PRIMARY KEY (name, deleted_transaction), 16 CONSTRAINT uq_caveat_v1 UNIQUE (name, created_transaction, deleted_transaction));`, 17 `ALTER TABLE relation_tuple 18 ADD COLUMN caveat_name VARCHAR, 19 ADD COLUMN caveat_context JSONB;`, 20 } 21 22 func init() { 23 if err := DatabaseMigrations.Register("add-caveats", "add-ns-config-id", 24 noNonatomicMigration, 25 func(ctx context.Context, tx pgx.Tx) error { 26 for _, stmt := range caveatStatements { 27 if _, err := tx.Exec(ctx, stmt); err != nil { 28 return err 29 } 30 } 31 32 return nil 33 }); err != nil { 34 panic("failed to register migration: " + err.Error()) 35 } 36 }