migration

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2022 License: MPL-2.0 Imports: 22 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) 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

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) CreateTable

func (m TableCreator) CreateTable(ctx context.Context, conn execution.QueryExecer, t, p *schema.Table) error

CreateTable generates CREATE TABLE definitions for the given table and runs them on the given conn

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) (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.

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