Metadata-Version: 2.1
Name: alchemy-modelgen
Version: 0.1.4
Summary: UNKNOWN
Home-page: https://github.com/shree14/sqlalchemy-modelgen
Author: Shrinivas Deshmukh
Author-email: shrinivas.deshmukh11@gmail.com
License: UNKNOWN
Platform: UNKNOWN
Description-Content-Type: text/markdown
Requires-Dist: alembic (>=1.5.8)
Requires-Dist: Cerberus (>=1.3.3)
Requires-Dist: inflect
Requires-Dist: Jinja2 (>=2.11.3)
Requires-Dist: mysql-connector-python (>=8.0.23)
Requires-Dist: psycopg2-binary (>=2.8.6)
Requires-Dist: python-dotenv (>=0.17.0)
Requires-Dist: PyYAML (>=5.4.1)
Requires-Dist: snowflake-sqlalchemy (>=1.2.4)
Requires-Dist: sqlacodegen (>=2.3.0)
Requires-Dist: SQLAlchemy (>=1.4.4)
Requires-Dist: sqlalchemy-redshift (>=0.8.2)


# sqlalchemy-modelgen

[![codecov](https://codecov.io/gh/shree14/sqlalchemy-modelgen/branch/main/graph/badge.svg?token=N0XQENE6IL)](https://codecov.io/gh/shree14/sqlalchemy-modelgen)


Create sqlalchemy python model files by defining tables and columns in a yaml file or by specifying database url

# Installation

```
pip install alchemy-modelgen
```

# Usage

<ol>

**<li> Initialize modelgen folder:</li>**

```
modelgen init -d /path/to/YOUR_FOLDER
cd /path/to/YOUR_FOLDER
```
<br />

**<li> Create sqlalchemy model code from: </li>** 

 **(Option 1)** `yaml` template:

**For details on how to write the yaml file, please follow [docs](https://github.com/shree14/sqlalchemy-modelgen/blob/main/docs/yaml_creation.md)**
```
modelgen createmodel --source yaml --path templates/example.yaml --alembic # path to your schema yaml file 
```
   **(Option 2)** existing `database`: 
```
modelgen createmodel --source database --path mysql+mysqlconnector://root:example@localhost:3306/modelgen --outfile models/YOUR_FILENAME.py --alembic
```
<br />

**<li> Running alembic migrations:</li>**

```
alembic revision --autogenerate -m "COMMIT_MESSAGE"
alembic upgrade head
```
<br />

**<li> Alter table support:</li>**

* Change column type, length, add contraint, etc in the yaml file. Then run:
```
modelgen createmodel --source yaml --path templates/example.yaml --alembic
alembic revision --autogenerate -m "COMMIT_MESSAGE"
alembic upgrade head
```

<ol>

## Credits

* The code that reads the structure of an existing database and generates the appropriate SQLAlchemy model code is based on [agronholm/sqlacodegen's](https://github.com/agronholm/sqlacodegen) repository (Copyright (c) Alex Grönholm), license: [MIT License](https://github.com/agronholm/sqlacodegen/blob/master/LICENSE)

