Configuration
Create a proper.json file
in your project root:
{
"database": "sqlite",
"sqlite": {
"database": "./data/app.sqlite"
},
"migration_folder": "migrations",
"migration_table": "proper_migrations"
}Configuration Options
| Option | Type | Description |
|---|---|---|
| database | string | Database type (currently "sqlite") |
| sqlite.database | string | Path to the SQLite database file |
| migration_folder | string | Directory containing migration files |
| migration_table | string | Table name for tracking applied migrations |
Creating Migrations
Create a new migration using the create command:
npx proper create create_usersThis creates two files in your migrations folder:
migrations/ ├── 20240115120000_create_users.up.sql └── 20240115120000_create_users.down.sql
File Naming Convention
Migration files are named with a timestamp prefix (YYYYMMDDHHMMSS)
followed by an underscore and the migration name. This ensures migrations are applied in chronological order.
Up Migration
The up migration contains SQL to apply the schema changes:
-- migrations/20240115120000_create_users.up.sql
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
email TEXT NOT NULL UNIQUE,
password_hash TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_users_email ON users(email);Down Migration
The down migration contains SQL to revert the changes:
-- migrations/20240115120000_create_users.down.sql
DROP INDEX IF EXISTS idx_users_email;
DROP TABLE IF EXISTS users;Best Practice
Always write reversible migrations. The down migration should cleanly undo everything
the up migration does. Use IF EXISTS clauses
to prevent errors on rollback.
Running Migrations
Apply Pending Migrations
Run all migrations that haven't been applied yet:
npx proper upRollback Last Migration
Revert the most recently applied migration:
npx proper downReset Database
Rollback all migrations and reapply them from scratch:
npx proper resetCheck Migration Status
See which migrations have been applied and which are pending:
npx proper status