Lightweight and secure database migration tool for Node.js and Postgres. Podil lets you version your database schema by executing SQL scripts automatically on application startup. It keeps track of what scripts have been executed and what not which lets you seamlessly update your database schema on every environment in the same way. Podil saves you from mistakingly breaking your schema by storing and verifying checksums of every script that it executed. Podil strives at being simple and minimalistic, that's why it brings no dependencies except for Podil itself.
Install Podil and pg:
npm install podil pg
Create a migrations
folder in the folder from which you start your
application (usually the project root) and add .sql
scripts to it.
.
βββ migrations
β βββ 001__init_schema.sql
β βββ 002__add_orders_table.sql
β βββ 003__add_order_status_column.sql
In the code, import podil
:
import { podil } from 'podil';
Add the migration call at the entry point of your application:
await podil.migrate('postgres://podil:podil@localhost:5432/podil');
This will execute all migrations. Note, the SQL files will be executed in the lexicographical order.
Podil can be configured to look for migration scripts in an arbitrary location.
By default, it looks for migrations in ./migrations
, you can pass a custom
folder in the following way:
await podil.migrate(
connectionString,
{ migrationsDir: '/path/to/your/migrations' },
);
It is recommended to verify the checksums of your scripts on every run. However,
you can disable checksum verification using the verifyChecksum
property:
await podil.migrate(
connectionString,
{ verifyChecksum: false },
);
Podil is in active development. If you found a bug, have a question or want to request a new feature, please open an issue.