mssql

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 7 Imported by: 0

README

SQL Server

Here is a basic example of setting up database migrations for SQL Server. To use the migrations tool with this provider, the connection string to the database must be defined in an environment variable CONNECTION_STRING.

Connection String

The connection string must be in this format: sqlserver://<username>:<password>@<host>?database=<database>. This is defined by the SQL Server driver, github.com/denisenkom/go-mssqldb.

History

With the SQL Server provider, migration history is stored in a SQL table, named __MigrationHistory. This table is used to record what migrations have been applied, and when.

The structure of the table is as follows:

Column Type Allow Null
Id INT No IDENTITY(1,1)
Name VARCHAR(255) No
DateApplied DATETIME No
Configuration

When it comes to the migration configuration file, the provider property must be set to mssql.

Optionally, the migration history table name can be configured using the config map, config. A property named historyTableName, can be used to configure the history table name. If not set, the default value __MigrationHistory, will be used.

# migrations.yaml
provider: mssql
config:
    historyTableName: MyMigrations # default: __MigrationHistory
migrations:
    - name: InitialCreation
      upFile: initialCreation.up.sql
      downFile: initialCreation.down.sql

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New returns a new instabnce of MSSQL. Implementing providers.ConstructorFunc, New takes a migrations.ConfigMap, which is used to populate HistoryTableName.

Types

type MSSQL

type MSSQL struct {
	ConnectionString string
	HistoryTableName string
}

MSSQL is a migration provider for SQL Server.

func (*MSSQL) Apply

func (p *MSSQL) Apply(ctx context.Context, name, content string) error

Apply applies the migration, m, to the database, as well as adding a record to the migration history table.

func (*MSSQL) GetAppliedMigrations

func (p *MSSQL) GetAppliedMigrations(ctx context.Context) ([]*migrations.Migration, error)

GetAppliedMigrations queries the migration history table for all applied migrations.

func (*MSSQL) Rollback

func (p *MSSQL) Rollback(ctx context.Context, name, content string) error

Rollback rolls back the migration, m, then removed the record from the migration history table.

Jump to

Keyboard shortcuts

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