No project description provided
Project description
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
- Initialize modelgen folder:
- Create sqlalchemy model code from:
- Running alembic migrations:
- Alter table support:
- Change column type, length, add contraint, etc in the yaml file. Then run:
- The code that reads the structure of an existing database and generates the appropriate SQLAlchemy model code is based on agronholm/sqlacodegen's repository (Copyright (c) Alex Grönholm), license: MIT License
modelgen init -d /path/to/YOUR_FOLDER
cd /path/to/YOUR_FOLDER
(Option 1) yaml
template:
For details on how to write the yaml file, please follow docs
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
alembic revision --autogenerate -m "COMMIT_MESSAGE"
alembic upgrade head
modelgen createmodel --source yaml --path templates/example.yaml --alembic
alembic revision --autogenerate -m "COMMIT_MESSAGE"
alembic upgrade head
Credits
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for alchemy_modelgen-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16fc112118bbc42a142ef13aceb0ea47e175193f33e6f6b390819715ee200931 |
|
MD5 | a51f7f736434dc2488610079470ee748 |
|
BLAKE2b-256 | f585f80c3d19241f0880bf4ba9b8e2873f64ca803b2f23edcea89f612948b3e9 |