0.1.1 • Published 10 months ago

cca-migration-generator v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
10 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

10 months ago

0.0.84

10 months ago

0.0.40

10 months ago

0.0.85

10 months ago

0.0.41

10 months ago

0.0.86

10 months ago

0.0.42

10 months ago

0.0.87

10 months ago

0.0.43

10 months ago

0.0.88

10 months ago

0.0.44

10 months ago

0.0.89

10 months ago

0.0.45

10 months ago

0.0.46

10 months ago

0.0.47

10 months ago

0.0.80

10 months ago

0.0.81

10 months ago

0.0.82

10 months ago

0.0.83

10 months ago

0.0.39

10 months ago

0.0.73

10 months ago

0.0.74

10 months ago

0.0.75

10 months ago

0.0.76

10 months ago

0.0.77

10 months ago

0.0.78

10 months ago

0.0.79

10 months ago

0.0.70

10 months ago

0.0.71

10 months ago

0.0.72

10 months ago

0.1.0

10 months ago

0.0.62

10 months ago

0.0.63

10 months ago

0.0.64

10 months ago

0.0.65

10 months ago

0.0.66

10 months ago

0.0.67

10 months ago

0.0.69

10 months ago

0.0.60

10 months ago

0.0.61

10 months ago

0.0.59

10 months ago

0.0.51

10 months ago

0.0.52

10 months ago

0.0.53

10 months ago

0.0.54

10 months ago

0.0.55

10 months ago

0.0.56

10 months ago

0.0.57

10 months ago

0.0.58

10 months ago

0.0.90

10 months ago

0.0.50

10 months ago

0.0.48

10 months ago

0.0.49

10 months ago

0.0.20

11 months ago

0.0.21

11 months ago

0.0.22

11 months ago

0.0.23

11 months ago

0.0.24

11 months ago

0.0.25

11 months ago

0.0.37

10 months ago

0.0.15

11 months ago

0.0.38

10 months ago

0.0.16

11 months ago

0.0.17

11 months ago

0.0.18

11 months ago

0.0.19

11 months ago

0.0.30

11 months ago

0.0.31

11 months ago

0.0.32

11 months ago

0.0.10

11 months ago

0.0.33

11 months ago

0.0.11

11 months ago

0.0.34

11 months ago

0.0.12

11 months ago

0.0.35

11 months ago

0.0.13

11 months ago

0.0.36

10 months ago

0.0.14

11 months ago

0.0.26

11 months ago

0.0.9

11 months ago

0.0.27

11 months ago

0.0.28

11 months ago

0.0.29

11 months ago

0.0.8

11 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago