cca-migrations
v0.1.1
Published
A powerful PostgreSQL migration tool with support for TypeORM and NestJS
Downloads
71
Maintainers
Readme
CCA-Migrations
A powerful PostgreSQL migration tool with support for TypeORM and NestJS. This tool helps you manage database migrations with ease and provides a simple CLI interface.
Features
- PostgreSQL database support
- TypeORM integration
- Migration management (run, revert, fix, force)
- Support for custom migration files
- Transaction support
- Detailed logging
Configuration
Create a db.config.json
file in your project root:
{
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "your_username",
"password": "your_password",
"database": "your_database"
}
Creating Migrations
- Create a
migrations
directory in your project root:
mkdir migrations
- Create a new migration file in the migrations directory. Migration files should follow this format:
module.exports = class YourMigrationName {
name = 'YourMigrationName'
async up(queryRunner) {
// Your migration code here
}
async down(queryRunner) {
// Your rollback code here
}
}
Usage
Running Migrations
npx cca-migrations run
Reverting Migrations
npx cca-migrations revert
Fixing Migrations
npx cca-migrations fix
Force Running Migrations
npx cca-migrations force
Example Migration
Here's an example migration that creates users and auth tables:
module.exports = class CreateUserAndAuthTables {
name = 'CreateUserAndAuthTables'
async up(queryRunner) {
await queryRunner.query(`
CREATE TABLE "users" (
"id" uuid NOT NULL DEFAULT uuid_generate_v4(),
"email" varchar NOT NULL,
"name" varchar NOT NULL,
CONSTRAINT "PK_users" PRIMARY KEY ("id")
)
`);
}
async down(queryRunner) {
await queryRunner.query(`DROP TABLE "users"`);
}
}
Error Handling
The tool provides detailed error messages and logging. If you encounter any issues:
- Check your database configuration
- Ensure migrations directory exists
- Verify migration file syntax
- Check database permissions
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Mindaugas Baltrunas [email protected]
Support
For support, email [email protected] or create an issue at https://github.com/minde8888/cca-migrations/issues