github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/internal/datastore/crdb/migrations/zz_migration.0004_add_caveats.go (about) 1 package migrations 2 3 import ( 4 "context" 5 6 "github.com/jackc/pgx/v5" 7 ) 8 9 const ( 10 createCaveatTable = `CREATE TABLE caveat ( 11 name VARCHAR NOT NULL, 12 definition BYTEA NOT NULL, 13 timestamp TIMESTAMP WITHOUT TIME ZONE DEFAULT now() NOT NULL, 14 CONSTRAINT pk_caveat_v1 PRIMARY KEY (name) 15 );` 16 17 addRelationshipCaveatContext = `ALTER TABLE relation_tuple 18 ADD COLUMN caveat_name VARCHAR, 19 ADD COLUMN caveat_context JSONB;` 20 ) 21 22 func init() { 23 err := CRDBMigrations.Register("add-caveats", "add-metadata-and-counters", addCaveatFunc, noAtomicMigration) 24 if err != nil { 25 panic("failed to register migration: " + err.Error()) 26 } 27 } 28 29 func addCaveatFunc(ctx context.Context, conn *pgx.Conn) error { 30 if _, err := conn.Exec(ctx, createCaveatTable); err != nil { 31 return err 32 } 33 if _, err := conn.Exec(ctx, addRelationshipCaveatContext); err != nil { 34 return err 35 } 36 return nil 37 }