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
modelgen migrate revision --autogenerate -m "COMMIT_MESSAGE" -p mysql+mysqlconnector://root:example@localhost:3306/modelgen
modelgen migrate upgrade head -p mysql+mysqlconnector://root:example@localhost:3306/modelgen
The arguments passed after modelgen migrate are based on alembic. Any command true for alembic can be used with modelgen migrate.
The database url can be passed using -p or --path argument, or can be set in the environment by the env var DATABASE_URI. If DATABASE_URI is set, -p or --path will be ignored
modelgen createmodel --source yaml --path templates/example.yaml --alembic
modelgen migrate revision --autogenerate -m "COMMIT_MESSAGE" -p mysql+mysqlconnector://root:example@localhost:3306/modelgen
modelgen migrate upgrade head -p mysql+mysqlconnector://root:example@localhost:3306/modelgen
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file alchemy_modelgen-0.1.6.1-py3.8.egg.
File metadata
- Download URL: alchemy_modelgen-0.1.6.1-py3.8.egg
- Upload date:
- Size: 32.3 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
162a3e92c19a72c1e0ae1e49b18dcf42b75d832793d8c0e0ef1ea89f820dce93
|
|
| MD5 |
2b3102e94541dd0f5fbcb7d83cf40102
|
|
| BLAKE2b-256 |
b078a93aef3c13ad6c78322a477c2bd4ec4a7da6107dffa47de2f3871f89c252
|
File details
Details for the file alchemy_modelgen-0.1.6.1-py3-none-any.whl.
File metadata
- Download URL: alchemy_modelgen-0.1.6.1-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec2a1425759af37043edc4197eb7c1bf604cdb20c533a7db1edfe01181cf7e2e
|
|
| MD5 |
64d14627124695527661775697fbf4bd
|
|
| BLAKE2b-256 |
868908e6d7639745cb97cda14fe417edce1f34fb6674d044f0fcaf12305e2fbf
|