Documentation
¶
Index ¶
- Variables
- type DistributedMigrationsTableConfig
- type LocalMigrationsTableConfig
- type Store
- func (s *Store) CreateVersionTable(ctx context.Context, tx database.DBTxConn) error
- func (s *Store) Delete(ctx context.Context, tx database.DBTxConn, version int64) error
- func (s *Store) GetLatestVersion(ctx context.Context, tx database.DBTxConn) (int64, error)
- func (s *Store) GetMigration(ctx context.Context, tx database.DBTxConn, version int64) (*database.GetMigrationResult, error)
- func (s *Store) Insert(ctx context.Context, tx database.DBTxConn, req database.InsertRequest) error
- func (s *Store) ListMigrations(ctx context.Context, tx database.DBTxConn) ([]*database.ListMigrationsResult, error)
- func (s *Store) Tablename() string
- func (s *Store) TablenameFullDistributed() string
- func (s *Store) TablenameFullLocal() string
Constants ¶
This section is empty.
Variables ¶
var DistributedMigrationsTableConfigByDefault = DistributedMigrationsTableConfig{
Cluster: "default",
ShardingKey: "rand()",
MutationsSync: 2,
}
var LocalMigrationsTableConfigByDefault = LocalMigrationsTableConfig{
ReplicaName: "{replica}",
}
Functions ¶
This section is empty.
Types ¶
type DistributedMigrationsTableConfig ¶
type DistributedMigrationsTableConfig struct {
Cluster string
Database string
TableName string
ShardingKey string
// MutationsSync controls the mutations_sync setting applied to the ALTER TABLE ... DELETE
// statement in Delete: 0 - async, 1 - wait for the current server, 2 - wait for all replicas.
MutationsSync uint8
}
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func NewStore ¶
func NewStore( distributedMigrationsTableConfig DistributedMigrationsTableConfig, localMigrationsTableConfig LocalMigrationsTableConfig, ) (*Store, error)
func (*Store) CreateVersionTable ¶
CreateVersionTable creates the version table, which is used to track migrations.
func (*Store) GetLatestVersion ¶
GetLatestVersion retrieves the last applied migration version. If no migrations exist, this method must return [ErrVersionNotFound].
func (*Store) GetMigration ¶
func (s *Store) GetMigration( ctx context.Context, tx database.DBTxConn, version int64, ) (*database.GetMigrationResult, error)
GetMigration retrieves a single migration by version id. If the query succeeds, but the version is not found, this method must return [ErrVersionNotFound].
func (*Store) ListMigrations ¶
func (s *Store) ListMigrations(ctx context.Context, tx database.DBTxConn) ([]*database.ListMigrationsResult, error)
ListMigrations retrieves all migrations sorted in descending order by id or timestamp. If there are no migrations, return an empty slice with no error. Typically, this method will return at least one migration because the initial version (0) is always inserted into the version table when it is created.