github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/internal/datastore/postgres/migrations/zz_migration.0015_add_gc_covering_index.go (about)

     1  package migrations
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/jackc/pgx/v5"
     7  )
     8  
     9  // See https://www.postgresql.org/docs/current/indexes-index-only-scans.html
    10  const createRelationTupleDeletedCoveringIndex = `CREATE INDEX CONCURRENTLY 
    11  	IF NOT EXISTS ix_relation_tuple_by_deleted_xid
    12  	ON relation_tuple (deleted_xid)
    13  	WHERE (deleted_xid::text::bigint < 9223372036854775807);`
    14  
    15  func init() {
    16  	if err := DatabaseMigrations.Register("add-gc-covering-index", "drop-bigserial-ids",
    17  		func(ctx context.Context, conn *pgx.Conn) error {
    18  			if _, err := conn.Exec(ctx, createRelationTupleDeletedCoveringIndex); err != nil {
    19  				return err
    20  			}
    21  			return nil
    22  		},
    23  		noTxMigration); err != nil {
    24  		panic("failed to register migration: " + err.Error())
    25  	}
    26  }