PostgreSQL TypeORM migration generator and schema builder with advanced TypeScript support
npm install cca-migration-generatorcca-migration-generator is a CLI tool that streamlines the creation of TypeORM migrations and table schemas for PostgreSQL databases. It offers seamless TypeScript integration and automated migration file generation.
bash
npx cca-migration-generator CreateUserTable
`
Getting Started
$3
Create a cca.config.json file in your project root:
`json
{
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "username",
"password": "your_password",
"database": "your_database"
}
`
$3
Create a .env file with your database configuration:
`env
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=your_username
DB_PASSWORD=your_password
DB_NAME=your_database
NODE_ENV=development
`
$3
Recommended project structure:
`
your-project/
├── src/
| ├── infrastructure/
| │ ├── database/
| │ │ ├── migrations/
| │ │ │ └── [migration files]
| │ │ └── config.ts
| │ └── entities/
| │ └── [entity files]
├── cca.config.json
└── .env
`
$3
Create a config.ts file for TypeORM configuration:
`typescript
// src/database/config.ts
export const dataSourceConfig = {
type: 'postgres',
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT || '5432'),
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
entities: [
// List your entity classes here
],
migrations: [
// Path to your migrations folder
],
synchronize: false, // Enable only in development
logging: true,
};
`
Features
- Automated TypeORM migration file generation
- PostgreSQL schema management
- TypeScript support with type definitions
- Flexible configuration options
- Custom migration templates
- Support for complex database relationships
- Automatic timestamp handling
Error Handling
$3
#### Configuration Errors
- Config file not found: Ensure cca.config.json exists in your project root
- Invalid configuration: Verify database credentials in cca.config.json or .env`