Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/raph6/migration
db migrations in golang
https://github.com/raph6/migration
database migration migration-tool migrations mysql pgx phinx postgresql sqlite sqlite3 sqlx
Last synced: about 1 month ago
JSON representation
db migrations in golang
- Host: GitHub
- URL: https://github.com/raph6/migration
- Owner: raph6
- Created: 2023-01-24T18:39:06.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-30T10:15:02.000Z (7 months ago)
- Last Synced: 2024-09-28T15:41:37.626Z (about 2 months ago)
- Topics: database, migration, migration-tool, migrations, mysql, pgx, phinx, postgresql, sqlite, sqlite3, sqlx
- Language: Go
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Migration for Golang
Currently only works with `github.com/jmoiron/sqlx`.## How to use
Install : `go get -u github.com/raph6/migration`Create a `migrations` folder in the root of the project and upload your `.sql` files as `ID_name_of_migration.sql`.
Example: `10001_create_accounts_table.sql`
Can contain several SQL queries such as :
```sql
-- 10001_create_accounts_table.sql
CREATE TABLE `accounts` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`username` VARCHAR(255) NOT NULL,
`password` VARCHAR(255) NOT NULL
);
``````sql
-- 10002_add_admin_to_accounts_table.sql
ALTER TABLE `accounts` ADD COLUMN `secret_token` varchar(200) DEFAULT NULL;ALTER TABLE `accounts` ADD COLUMN `admin` TINYINT(1) NOT NULL DEFAULT 0;
```Please note, do not set file IDs to 1, 2, 3... 10, 11, 12, otherwise files 10, 11, 12 will be read before 1, 2, 3.
I advise you to start at 10000 and then increment or take the timestamp of the file creation.
## Run
```go
import "github.com/raph6/migration"func main() {
var db *sqlx.DB
db = ...migration.Migrate(db)
}
```## Incoming
- [ ] Migration revert