Previous
Migrations
Next
None
Seeding Data
Proper also supports database seeding for test data or initial configuration. Add seed
configuration to your proper.json:
{
"database": "sqlite",
"sqlite": {
"database": "./data/app.sqlite"
},
"migration_folder": "migrations",
"migration_table": "proper_migrations",
"seed": {
"folder": "seeds",
"table": "proper_seeds"
}
}Seed Files
Seed files follow the same up/down pattern as migrations:
-- seeds/001_sample_users.up.sql
INSERT INTO users (email, password_hash) VALUES
('admin@example.com', '$2b$10$...'),
('user@example.com', '$2b$10$...');-- seeds/001_sample_users.down.sql
DELETE FROM users WHERE email IN ('admin@example.com', 'user@example.com');Apply Seeds
npx proper seed upRollback Seeds
npx proper seed downCommand Reference
| Command | Description |
|---|---|
| npx proper create <name> | Create a new migration with the given name |
| npx proper up | Apply all pending migrations |
| npx proper down | Rollback the last applied migration |
| npx proper reset | Rollback all migrations and reapply them |
| npx proper status | Show migration status and pending migrations |
| npx proper seed up | Run all pending seed files |
| npx proper seed down | Rollback the last applied seed |
Typical Workflow
1
Create a migration
npx proper create add_posts_table2
Write the up and down SQL
Edit the generated .up.sql and .down.sql files
3
Apply the migration
npx proper up4
Verify with status
npx proper status5
Commit the migration files
Add migration files to version control
Previous
Migrations
Next
None