migration

package
v0.8.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2022 License: MPL-2.0 Imports: 24 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateDiff

func GenerateDiff(ctx context.Context, logger hclog.Logger, conn *pgxpool.Conn, schemaName string, dialectType schema.DialectType, p *provider.Provider, outputPath, prefix string, fakeTSDB bool) error

GenerateDiff creates incremental table migrations for the provider based on it's ResourceMap. Entities are compared to a given conn.

func GenerateFull

func GenerateFull(ctx context.Context, logger hclog.Logger, p *provider.Provider, dialects []schema.DialectType, outputPath, prefix string) error

GenerateFull creates initial table migrations for the provider based on it's ResourceMap

func Run

func Run(ctx context.Context, p *provider.Provider, outputPath string) error

Run is the main entry point for CLI usage.

func RunMigrationsTest

func RunMigrationsTest(t *testing.T, prov *provider.Provider, additionalVersionsToTest []string)

RunMigrationsTest helper tests the migration files of the provider using the database (and dialect) specified in CQ_MIGRATION_TEST_DSN

func RunMigrationsTestWithNewDB added in v0.7.6

func RunMigrationsTestWithNewDB(t *testing.T, dbDSN string, newDBName string, prov *provider.Provider, additionalVersionsToTest []string)

Types

type TableCreator

type TableCreator struct {
	// contains filtered or unexported fields
}

TableCreator handles creation of schema.Table in database as SQL strings

func NewTableCreator

func NewTableCreator(log hclog.Logger, dialect schema.Dialect) *TableCreator

func (TableCreator) CreateTableDefinitions

func (m TableCreator) CreateTableDefinitions(ctx context.Context, t *schema.Table, parent *schema.Table) (up, down []string, err error)

CreateTableDefinitions reads schema.Table and builds the CREATE TABLE and DROP TABLE statements for it, also processing and returning subrelation tables

func (TableCreator) DiffTable

func (m TableCreator) DiffTable(ctx context.Context, conn *pgxpool.Conn, schemaName string, t, parent *schema.Table, fakeTSDB bool) (up, down []string, err error)

DiffTable reads current table info from the given conn for the given table, and returns ALTER TABLE ADD COLUMN statements for the missing columns. Newly appearing tables will return a CREATE TABLE statement. Column renames are detected (best effort) and ALTER TABLE RENAME COLUMN statements are generated as comments. Table renames or removals are not detected. FK changes are not detected. if fakeTSDB is set, PKs for existing resources are assumed to have fakeTSDBAssumeColumn (`cq_fetch_date`) as the first part of composite PK.

Directories

Path Synopsis
https://github.com/jpillora/longestcommon Doesn't have go.mod file
https://github.com/jpillora/longestcommon Doesn't have go.mod file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL