https://github.com/mdda/sqlalchemy-migrate-pylons
Simple script to migrate SQLalchemy databases used by Pylons
https://github.com/mdda/sqlalchemy-migrate-pylons
Last synced: 24 days ago
JSON representation
Simple script to migrate SQLalchemy databases used by Pylons
- Host: GitHub
- URL: https://github.com/mdda/sqlalchemy-migrate-pylons
- Owner: mdda
- Created: 2010-09-15T18:11:11.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2011-05-15T21:54:36.000Z (about 15 years ago)
- Last Synced: 2025-12-28T19:05:38.111Z (6 months ago)
- Language: Python
- Homepage: http://platformedia.com/oss-blog/sqlalchemy-model-migration/
- Size: 102 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
Stupidly simple SQLalchemy model migration
==========================================
This simple script pulls in the relavant database and model parameters from pylons .INI
It relies on the ``migrate`` egg for the ``diff`` and ``applyModel`` functions, and also makes use of the ConfigParser embedded in ``paste.deploy.loadwsgi``.
*It is most useful when rapidly developing / prototyping a Pylons application.*
Installation of required modules
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
easy_install SQLAlchemy
easy_install sqlalchemy-migrate
Setup of MYPROKJ .INI files and model meta files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Within the Pylons .INI file, it looks for a section called [app] *(the typical value is [app:main])*
2. The database URL is found from ``sqlalchemy.url`` :
``sqlalchemy.url = sqlite:///%(here)s/development.db``
3. The metadata for SQLalchemy is taken from a new entry : ``migrate.metadata`` :
``migrate.metadata = MYPROJ.model.meta:metadata``
Where the file MYPROJ/model/meta.py contains the following : ::
from sqlalchemy import schema
metadata = schema.MetaData()
# The declarative DataBase base Object
Base = declarative_base(metadata=metadata)
Syntax
------
(python-local) $ python sqlalchemy-migrate-pylons.py --help
Usage: sqlalchemy-migrate-pylons.py [options] STANDALONE.ini
Options:
-h, --help show this help message and exit
-a, --app section to parse in ini file (default=app:main)
-c, --commit Use diffs to update database (default=False)
-v, --verbose Show debug messages
Normal usage
------------
1. To check what needs to be changed:
``python sqlalchemy-migrate-pylons.py development.ini``
2. To implement the changes and report back:
``python sqlalchemy-migrate-pylons.py --commit development.ini``
Known Issues
------------
* Changing a model from ``nullable=True`` to ``nullable=False`` can be a problem, since the migrate package doesn't seem to understand ``default=''``
* The script is dependent on sqlalchemy-migrate, so could be incorporated into that package
* OTOH, it would probably sit better as a Paster-Pylons plug-in
* Please let me know if there are any other problems.
**As always : Back up your data before doing a migrate.**