- Created a README file for database migrations using node-pg-migrate, detailing commands, file format, best practices, and an example migration. - Added a Vite configuration file for the frontend, including plugin setup, alias resolution, build optimizations, and responsive design adjustments for task list components. - Updated i18n configuration to preload the 'home' namespace for improved localization. - Enhanced task list styling with responsive design features for better mobile usability.
2.1 KiB
2.1 KiB
Node-pg-migrate Migrations
This directory contains database migrations managed by node-pg-migrate.
Migration Commands
npm run migrate:create -- migration-name- Create a new migration filenpm run migrate:up- Run all pending migrationsnpm run migrate:down- Rollback the last migrationnpm run migrate:redo- Rollback and re-run the last migration
Migration File Format
Migrations are JavaScript files with timestamp prefixes (e.g., 20250115000000_performance-indexes.js).
Each migration file exports two functions:
exports.up- Contains the forward migration logicexports.down- Contains the rollback logic
Best Practices
- Always use IF EXISTS/IF NOT EXISTS checks to make migrations idempotent
- Test migrations locally before deploying to production
- Include rollback logic in the
downfunction for all changes - Use descriptive names for migration files
- Keep migrations focused - one logical change per migration
Example Migration
exports.up = pgm => {
// Create table with IF NOT EXISTS
pgm.createTable('users', {
id: 'id',
name: { type: 'varchar(100)', notNull: true },
created_at: {
type: 'timestamp',
notNull: true,
default: pgm.func('current_timestamp')
}
}, { ifNotExists: true });
// Add index with IF NOT EXISTS
pgm.createIndex('users', 'name', {
name: 'idx_users_name',
ifNotExists: true
});
};
exports.down = pgm => {
// Drop in reverse order
pgm.dropIndex('users', 'name', {
name: 'idx_users_name',
ifExists: true
});
pgm.dropTable('users', { ifExists: true });
};
Migration History
The pgmigrations table tracks which migrations have been run. Do not modify this table manually.
Converting from SQL Migrations
When converting SQL migrations to node-pg-migrate format:
- Wrap SQL statements in
pgm.sql()calls - Use node-pg-migrate helper methods where possible (createTable, addColumns, etc.)
- Always include
IF EXISTS/IF NOT EXISTSchecks - Ensure proper rollback logic in the
downfunction