https://github.com/bytemedirk/model-view-controller
https://github.com/bytemedirk/model-view-controller
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bytemedirk/model-view-controller
- Owner: ByteMeDirk
- License: apache-2.0
- Created: 2024-08-24T13:45:01.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-08-27T06:42:10.000Z (10 months ago)
- Last Synced: 2025-01-13T10:49:57.167Z (5 months ago)
- Language: Python
- Size: 46.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Model View Controller (MVC) Database Schema Manager
This package provides a flexible and powerful tool for managing database schemas using a Model-View-Controller (MVC)
architecture. It allows you to define your database models using YAML configuration files and automatically build,
update, or drop database tables based on these configurations.## Features
- **YAML-based Model Definition**: Define your database models using simple YAML configuration files.
- **Automatic Schema Management**: Create, update, or drop database tables based on your model definitions.
- **Schema Comparison**: Automatically detect and apply changes to existing tables.
- **Force Mode**: Option to force updates even when data loss might occur.
- **Flexible Column Types**: Support for a wide range of SQL column types.
- **Database Agnostic**: Works with any database supported by SQLAlchemy.
- **CLI Interface**: Easy-to-use command-line interface for managing your database schema.
- **Logging**: Detailed logging of all operations for easy troubleshooting.## Installation
```bash
pip install model-view-controller
```## Usage
### Directory Structure
Create a directory for your project with the following structure:
```
your_project/
├── config.yaml
├── model1.yaml
├── model2.yaml
└── ...
```### Configuration
1. Create a `config.yaml` file in your project directory:
```yaml
database:
connection: "postgresql://username:password@localhost:5432/dbname"
schema: "public"
```2. Define your models in separate YAML files:
```yaml
# users.yaml
columns:
- name: id
type: integer
primary_key: true
auto_increment: true
- name: name
type: string
length: 100
- name: email
type: string
length: 100
description: "Users table"
```### CLI Commands
#### Build Schema
To build or update your database schema:
```bash
mvc build /path/to/your/project
```Options:
- `--force`: Force column deletion even if it contains data
- `--drop-tables`: Drop tables that exist in the database but not in configs#### Drop Schema
To drop all tables from the database schema:
```bash
mvc drop /path/to/your/project
```Options:
- `--force`: Force drop without confirmation
## Advanced Features
### Column Type Mapping
The package supports a wide range of SQL column types, including:
- Integer types: `integer`, `bigint`, `smallint`
- String types: `string`, `text`
- Floating-point types: `float`, `real`, `double`, `decimal`, `numeric`
- Date and time types: `datetime`, `timestamp`, `time`, `date`
- Binary types: `binary`, `large_binary`
- Boolean type: `boolean`
- Unicode types: `unicode`, `unicode_text`### Schema Comparison and Updates
When running the `build` command, the tool will:
1. Compare existing table schemas with the defined models
2. Add new columns as needed
3. Remove deleted columns (with confirmation or using `--force`)
4. Update column types if they have changed### Logging
The package provides detailed logging of all operations, making it easy to track changes and troubleshoot issues.