Page 1 of 2
Previous
None
Next
Seeding Data

Configuration

Create a proper.json file in your project root:

proper.json
{
  "database": "sqlite",
  "sqlite": {
    "database": "./data/app.sqlite"
  },
  "migration_folder": "migrations",
  "migration_table": "proper_migrations"
}

Configuration Options

OptionTypeDescription
databasestringDatabase type (currently "sqlite")
sqlite.databasestringPath to the SQLite database file
migration_folderstringDirectory containing migration files
migration_tablestringTable name for tracking applied migrations

Creating Migrations

Create a new migration using the create command:

terminal
npx proper create create_users

This 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:

20240115120000_create_users.up.sql
-- 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:

20240115120000_create_users.down.sql
-- 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:

terminal
npx proper up

Rollback Last Migration

Revert the most recently applied migration:

terminal
npx proper down

Reset Database

Rollback all migrations and reapply them from scratch:

terminal
npx proper reset

Check Migration Status

See which migrations have been applied and which are pending:

terminal
npx proper status
Page 1 of 2
Previous
None
Next
Seeding Data
NoEgo

© 2025 NoEgo. All rights reserved.