SQL migration
A blueprint that creates a pair of migration files: one that creates a table and one that drops it. The migration number and the table name are entered when the blueprint runs.
Config
Section titled “Config”module.exports = { blueprints: [ { title: "SQL migration", variables: [ { key: "version", prompt: "Migration number (e.g. 001)" }, { key: "table", prompt: "Table name (e.g. users)" }, ], snippets: { up: `CREATE TABLE {table.snake} ( id BIGINT PRIMARY KEY, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP);`, down: `DROP TABLE IF EXISTS {table.snake};`, }, structure: { files: [ { name: "{version.raw}_create_{table.snake}.up.sql", snippet: "up" }, { name: "{version.raw}_create_{table.snake}.down.sql", snippet: "down" }, ], }, }, ],};-
Right-click your migrations folder (for example
db/migrations) and choose Run Blueprintor…. -
Select SQL migration.
-
Enter
001as the number, thenusersas the table name.
Result
Section titled “Result”Directorydb
Directorymigrations
- 001_create_users.up.sql
- 001_create_users.down.sql
CREATE TABLE users ( id BIGINT PRIMARY KEY, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP);DROP TABLE IF EXISTS users;{table.snake} turns a name such as user profile or UserProfile into user_profile, which is the usual style for table names.