adding sqlalchemy-migrate glue

* add a product and producttype table (addresses #1)
 * add a person table and reference to customers table (fixes #8)
 * use sqlalchemy-migrate's API to setup database and add
   configuration for the sqlalchemy-migrate calls to development.ini
   and the paste_deploy template (fixes #7)


git-svn-id: file:///var/www/wwwusers/usr01/svn/pyalchemybiz/trunk@7 389c73d4-bf09-4d3d-a15e-f94a37d0667a
This commit is contained in:
Jan Dittberner 2008-10-05 21:02:10 +00:00
parent ab91d92af3
commit 1228fcef3c
16 changed files with 183 additions and 12 deletions

4
data/dbrepo/README Normal file
View file

@ -0,0 +1,4 @@
This is a database migration repository.
More information at
http://code.google.com/p/sqlalchemy-migrate/

0
data/dbrepo/__init__.py Normal file
View file

4
data/dbrepo/manage.py Normal file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
from migrate.versioning.shell import main
main(repository='data/dbrepo')

20
data/dbrepo/migrate.cfg Normal file
View file

@ -0,0 +1,20 @@
[db_settings]
# Used to identify which repository this database is versioned under.
# You can use the name of your project.
repository_id=pyalchemybiz
# The name of the database table used to track the schema version.
# This name shouldn't already be used by your project.
# If this is changed once a database is under version control, you'll need to
# change the table name in each database too.
version_table=migrate_version
# When committing a change script, Migrate will attempt to generate the
# sql for all supported databases; normally, if one of them fails - probably
# because you don't have that database installed - it is ignored and the
# commit continues, perhaps ending successfully.
# Databases in this list MUST compile successfully during a commit, or the
# entire commit will fail. List the databases your application will actually
# be using to ensure your updates to that database work properly.
# This must be a list; example: ['postgres','sqlite']
required_dbs=[]

View file

@ -0,0 +1,29 @@
from sqlalchemy import MetaData, Table, Column, ForeignKey, types
from migrate import *
def upgrade():
# Upgrade operations go here. Don't create your own engine; use the engine
# named 'migrate_engine' imported from migrate.
meta = MetaData(bind=migrate_engine)
t_product_type = Table(
'producttype', meta,
Column('id', types.Integer, primary_key=True),
Column('name', types.Unicode(40), nullable=False),
Column('description', types.UnicodeText(), nullable=False))
t_product_type.create()
t_product = Table(
'product', meta,
Column('id', types.Integer, primary_key=True),
Column('name', types.Unicode(100), nullable=False),
Column('description', types.UnicodeText(), nullable=False),
Column('producttype_id', types.Integer,
ForeignKey(t_product_type.c.id), nullable=False))
t_product.create()
def downgrade():
# Operations to reverse the above upgrade go here.
meta = MetaData(bind=migrate_engine)
t_product = Table('product', meta, autoload=True)
t_product.drop()
t_product_type = Table('product_type', meta, autoload=True)
t_product_type.drop()

View file

@ -0,0 +1,27 @@
from sqlalchemy import MetaData, Table, Column, ForeignKey, types
from migrate import *
def upgrade():
# Upgrade operations go here. Don't create your own engine; use the engine
# named 'migrate_engine' imported from migrate.
meta = MetaData(bind=migrate_engine)
t_person = Table(
'person', meta,
Column('id', types.Integer, primary_key=True),
Column('firstname', types.Unicode(100), nullable=False),
Column('lastname', types.Unicode(100), nullable=False))
t_person.create()
t_customer = Table(
'customer', meta,
Column('id', types.Integer, primary_key=True),
Column('person_id', types.Integer, ForeignKey(t_person.c.id),
nullable=False, unique=True))
t_customer.create()
def downgrade():
# Operations to reverse the above upgrade go here.
meta = MetaData(bind=migrate_engine)
t_customer = Table('customer', meta, autoload=True)
t_customer.drop()
t_person = Table('person', meta, autoload=True)
t_person.drop()

View file