proxy.golang.org : github.com/jjeffery/migration
Package migration manages database schema migrations. There many popular packages that provide database migrations, so it is worth listing how this package is different. Database migrations are usually written in SQL/DDL using the dialect specific to the target database. Most of the time this is sufficient, but there are times when it is more convenient to specify a migration using Go code. Each database schema version has an "up" migration, which migrates up from the previous database schema version. It also has a "down" migration, which should revert the changes applied in the "up" migration. Database migrations are performed within a transaction if the database supports it. When a migration drops and recreates a view, it is necessary to restore the previous version of the view in the down migration, which results in duplicated code. (This problem also exists for stored procedures, functions, triggers, etc). This package provides a simple solution in the form af defining migrations as a replay of a previous "up" migration. The "down" migration for a create view can be defined as a replay of the prevous "up" migration that created the previous version of the view. Database schema versions are identified by positive 64-bit integers. Migrations can be defined in different VCS branches using an arbitrary naming convention, such as the current date and time. When branches are merged and a database migration is performed, any unapplied migrations will be applied in ascending order of database schema version. Once a set of migrations has been applied, the database schema version can be locked, which means that any attempt to migrate down past this version will fail. This is useful for avoiding accidents with production database schemas. Migrations are written as part of the Go source code, and are embedded in the resulting executable without the need for any embedding utility, or the need to deploy any separate text files. This package does not provide a stand-alone command line utility for managing database migrations. Instead it provides a simple API that can be utilized as part of a project-specific CLI for database management. The cli subdirectory contains a re-usable command line command based on the "github.com/spf13/cobra" package. If this package does not meet your needs, refer to https://github.com/avelino/awesome-go#database for a list popular database migration packages.
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/jjeffery/migration
License: MIT
Latest release: over 6 years ago
First release: over 6 years ago
Namespace: github.com/jjeffery
Last synced: 4 days ago