migrations

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

README

Migrations are in SQL files of the format TIMESTAMP_NAME.up.sql and TIMESTAMP_NAME.down.sql. Names do not necessarily need to be unique, but timestamps do. The .up.sql is done for schema upgrades, and .down.sql for when rolling back a schema upgrade. If it is unsafe to roll back, create a .down.sql file containing text to describe the reason that is not valid SQL.

Once a migration has been used on a real site, it should in general NEVER be changed so that we can maintain a consistent environment. If an exception needs to be made include a comment "-- Allow hash changing" to ignore this. All sites where it was deployed will require manual schema editing to be consistent with the new schema unless the change was to add an UPDATE or DELETE command to modify the data instead of the schema.

While developing, if you want to replace a version of a migration that was only present in a prior version of your workspace, manually undo the changes made to the schema, then either run the SQL "delete from migrations where id = 'TIMESTAMP'" or start using a new timestamp.

When a new version of nvswitch-manager is run, all .up.sql migrations that were not present before are run in a single transaction in the order of their timestamps.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, db *postgres.Postgres) error

Migrate ensures that the database contains all currently known migrations

func Rollback

func Rollback(ctx context.Context, db *postgres.Postgres, rollbackTime time.Time) error

Rollback will roll back migrations that have been applied since the given time

Types

This section is empty.

Jump to

Keyboard shortcuts

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