0.1.1 • Published 6 months ago

cca-migration-generator v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

CCA Migration Generator

A robust TypeORM migration and table schema generator for PostgreSQL with TypeScript support.

Overview

cca-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.

Prerequisites

  • Node.js >= 14
  • PostgreSQL >= 12
  • TypeORM >= 0.3.0
  • TypeScript >= 4.5

Usage

Basic Commands

Generate a new migration:

npx cca-migration-generator CreateUserTable

Getting Started

1. Database Configuration

Create a cca.config.json file in your project root:

{
  "type": "postgres",
  "host": "localhost",
  "port": 5432,
  "username": "username",
  "password": "your_password",
  "database": "your_database"
}

2. Environment Setup

Create a .env file with your database configuration:

DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=your_username
DB_PASSWORD=your_password
DB_NAME=your_database
NODE_ENV=development

3. Project Structure

Recommended project structure:

your-project/
├── src/
|   ├── infrastructure/
|   │   ├── database/
|   │   │   ├── migrations/
|   │   │   │   └── [migration files]
|   │   │   └── config.ts
|   │   └── entities/
|   │       └── [entity files]
├── cca.config.json
└── .env

4. DataSource Configuration

Create a config.ts file for TypeORM configuration:

// 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

Common Issues and Solutions

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
  • Connection failed: Check PostgreSQL server status and accessibility

Migration Errors

  • Duplicate migration: Each migration name must be unique
  • Invalid migration path: Verify migration directory configuration
  • Syntax error: Ensure TypeScript syntax is correct in migration files

Best Practices

Migration Management

  • Keep migrations atomic and focused
  • Use meaningful, descriptive migration names
  • Test migrations in development before deploying to production
  • Never modify existing migrations
  • Use transactions for complex migrations

Configuration

  • Store sensitive data in environment variables
  • Maintain separate configurations for development and production
  • Document configuration changes

Type Safety

  • Define TypeScript interfaces for entities
  • Use appropriate column types
  • Implement enums for predefined values

Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to your branch
  5. Create a Pull Request

Support

License

This project is licensed under the MIT License - see the LICENSE file for details.

0.1.1

6 months ago

0.0.84

6 months ago

0.0.40

6 months ago

0.0.85

6 months ago

0.0.41

6 months ago

0.0.86

6 months ago

0.0.42

6 months ago

0.0.87

6 months ago

0.0.43

6 months ago

0.0.88

6 months ago

0.0.44

6 months ago

0.0.89

6 months ago

0.0.45

6 months ago

0.0.46

6 months ago

0.0.47

6 months ago

0.0.80

6 months ago

0.0.81

6 months ago

0.0.82

6 months ago

0.0.83

6 months ago

0.0.39

6 months ago

0.0.73

6 months ago

0.0.74

6 months ago

0.0.75

6 months ago

0.0.76

6 months ago

0.0.77

6 months ago

0.0.78

6 months ago

0.0.79

6 months ago

0.0.70

6 months ago

0.0.71

6 months ago

0.0.72

6 months ago

0.1.0

6 months ago

0.0.62

6 months ago

0.0.63

6 months ago

0.0.64

6 months ago

0.0.65

6 months ago

0.0.66

6 months ago

0.0.67

6 months ago

0.0.69

6 months ago

0.0.60

6 months ago

0.0.61

6 months ago

0.0.59

6 months ago

0.0.51

6 months ago

0.0.52

6 months ago

0.0.53

6 months ago

0.0.54

6 months ago

0.0.55

6 months ago

0.0.56

6 months ago

0.0.57

6 months ago

0.0.58

6 months ago

0.0.90

6 months ago

0.0.50

6 months ago

0.0.48

6 months ago

0.0.49

6 months ago

0.0.20

7 months ago

0.0.21

7 months ago

0.0.22

7 months ago

0.0.23

7 months ago

0.0.24

7 months ago

0.0.25

7 months ago

0.0.37

6 months ago

0.0.15

7 months ago

0.0.38

6 months ago

0.0.16

7 months ago

0.0.17

7 months ago

0.0.18

7 months ago

0.0.19

7 months ago

0.0.30

7 months ago

0.0.31

7 months ago

0.0.32

7 months ago

0.0.10

7 months ago

0.0.33

7 months ago

0.0.11

7 months ago

0.0.34

7 months ago

0.0.12

7 months ago

0.0.35

7 months ago

0.0.13

7 months ago

0.0.36

6 months ago

0.0.14

7 months ago

0.0.26

7 months ago

0.0.9

7 months ago

0.0.27

7 months ago

0.0.28

7 months ago

0.0.29

7 months ago

0.0.8

7 months ago

0.0.7

7 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago