dbmigrations 0.3.0
Simple tool for managing Database migrations
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
Database migration tool
Database migration tool to apply all available migrations from db/migrations
(customizable) directory. It is inspired by micrate.
Usage
Create the migrations directory in your project directory. For example,
cd myproject
mkdir -p db/migrations
Export the DATABASE_URL. For example,
export DATABASE_URL=postgres://postgres:secret@localhost:5432/myapp_dev
For SQLite,
export DATABASE_URL=sqlite:////var/lib/myapp/myapp.db
Scaffold
Now create the migration file by running the below command.
$ dub run dbmigrations@0.3.0 scaffold -n users
Created ./db/migrations/20240524213223-users.sql
Open the file and add the SQL for upgrade under -- +UP
and downgrade SQL under -- +DOWN
section. Example,
-- +UP
-- SQL in section '+UP' is included when this migration is applied
CREATE TABLE users(
id BIGSERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
email VARCHAR NOT NULL,
password_hash VARCHAR NOT NULL,
created_at TIMESTAMP,
updated_at TIMESTAMP
);
-- +DOWN
-- SQL section '+DOWN' is included when this migration is rolled back
DROP TABLE users;
Upgrade
Run dbmigrations up
to apply all the available migrations.
$ dub run dbmigrations@0.3.0 up
OK 20240524135055-users
OK 20240524135713-api-keys
Status
Check the status of the migrations by running
$ dub run dbmigrations@0.3.0 status
Sep 02, 2024 06:09:50 20240524135055-users
pending 20240524135713-api-keys
Downgrade(one by one)
$ dub run dbmigrations@0.3.0 down
OK 20240524135713-api-keys
TODO:
- Postgres and SQLite are supported now, add support for MySQL.
Contributing
- Fork it (https://github.com/aravindavk/dbmigrations/fork)
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -asm 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- Aravinda VK - Creator and Maintainer
- 0.3.0 released 3 months ago
- aravindavk/dbmigrations
- MIT
- Copyright © 2024, Aravinda VK <mail@aravindavk.in>
- Authors:
- Dependencies:
- d2sqlite3, dpq2
- Versions:
-
0.3.0 2024-Sep-30 0.2.1 2024-Sep-02 0.2.0 2024-Sep-02 0.1.0 2024-Sep-02 ~main 2024-Sep-30 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
0 downloads total
-
- Score:
- 0.3
- Short URL:
- dbmigrations.dub.pm