SQLAlchemy Migration Maker
SQLalchemy 是個 Python 的 Database Library,可以與 Postgres、MySQL 與其他 Database 連結,但是卻缺少了更新 Database 的功能。
受到 Django Database 的啟發,我寫了這套件使更新更輕鬆,把 Database 結構化成特別的 Id,並存到資料庫,透過比較結構來決定需要下哪些 SQL 指令。
此套件需要自行設定
SQLalchemy is a python library that deal with database. Can be used to connect with Postgres, MySQL, etc. But it lack of builtin migrate functionality.
Inspire by django db manager, I write this package to migrate db more easily.
It turn Database structure into special id then store in database.
When there's new version structure, it compares two version then decide what SQL command need to be executed.
This package need to setup yourself
Intall
pip install sqlalchemy-migration-maker
Requiremnt
- sqlalchemy
Testing
Require psycopg2
In my testing, I use postgres database to execute sql language
Tested Envirment
- MacOSX
- Python3
Tested Database
- Postgres
Example
model.py
from sqlalchemy import Column
from sqlalchemy.types import Integer
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class User(Base):
__tablename__ = "user"
id = Column(Integer, primary_key=True, autoincrement=True)
def __repr__(self):
return f"<User {self.id} {self.create_at}>"
migrate.py
from .model import Base
from migrationmaker import VersionControl
version_ctl = VersionCtrol("{DB_URI}")
# 檢查版本控制是否存在於 DB
# Check version ctrl exist in DB
version_ctl.check_version_ctl_exist()
# 取回舊版本
# Retrieve old version
self.version_ctl.get_latest_version(is_old_metadata=True)
# 指定新版本
# Assign new version
self.version_ctl.new_version(Base.metadata)
if not self.version_ctl.check_same():
self.version_ctl.migrate()
Metadata
Release files for sqlalchemy-migration-maker 0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sqlalchemy-migration-maker-0.4.tar.gz | 7.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sqlalchemy_migration_maker-0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.5 kB
Release files / sqlalchemy-migration-maker-0.4.tar.gz
| Download URL | sqlalchemy-migration-maker-0.4.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6d0a91e2b8e5494626a269363f35d9db0fc46beceb291300c27bb3db88e995b2
|
|
BLAKE2b-256 checksum How to use checksums |
37fd16b6bc48707aa0e49db054b8987e3bdd817ff5d89f8c540ead57c177867b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5
|
Release files / sqlalchemy_migration_maker-0.4-py3-none-any.whl
| Download URL | sqlalchemy_migration_maker-0.4-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
655fa21ca053266bd040581fec0232b55d9d5684e898e6469fa0954e42cb6216
|
|
BLAKE2b-256 checksum How to use checksums |
bcbf0f25295e4da4fd59ad4610be4f3364f4108037333f1144dedbc2e46d76df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5
|