diff options
author | Jessica Tallon <jessica@megworld.co.uk> | 2014-09-15 19:34:42 +0100 |
---|---|---|
committer | Jessica Tallon <jessica@megworld.co.uk> | 2014-10-09 19:16:54 +0100 |
commit | c0434db46910e891313495b5ae94cbbe1dd08058 (patch) | |
tree | 9f7cfe31ca3bf4c5f49adf2daa964eafe91061dd /mediagoblin/db/migrations.py | |
parent | d60d686a14d10af3f58867569622735ff9ecd068 (diff) | |
download | mediagoblin-c0434db46910e891313495b5ae94cbbe1dd08058.tar.lz mediagoblin-c0434db46910e891313495b5ae94cbbe1dd08058.tar.xz mediagoblin-c0434db46910e891313495b5ae94cbbe1dd08058.zip |
Add location model and migrations
Diffstat (limited to 'mediagoblin/db/migrations.py')
-rw-r--r-- | mediagoblin/db/migrations.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index 04588ad1..be509a75 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -890,3 +890,40 @@ def revert_username_index(db): db.rollback() db.commit() + +class Location_V0(declarative_base()): + __tablename__ = "core__locations" + id = Column(Integer, primary_key=True) + name = Column(Unicode) + position = Column(MutationDict.as_mutable(JSONEncoded)) + address = Column(MutationDict.as_mutable(JSONEncoded)) + +@RegisterMigration(24, MIGRATIONS) +def add_location_model(db): + """ Add location model """ + metadata = MetaData(bind=db.bind) + + # Create location table + Location_V0.__table__.create(db.bind) + db.commit() + + # Inspect the tables we need + user = inspect_table(metadata, "core__users") + collections = inspect_table(metadata, "core__collections") + media_entry = inspect_table(metadata, "core__media_entries") + media_comments = inspect_table(metadata, "core__media_comments") + + # Now add location support to the various models + col = Column("location", Integer, ForeignKey(Location_V0.id)) + col.create(user) + + col = Column("location", Integer, ForeignKey(Location_V0.id)) + col.create(collections) + + col = Column("location", Integer, ForeignKey(Location_V0.id)) + col.create(media_entry) + + col = Column("location", Integer, ForeignKey(Location_V0.id)) + col.create(media_comments) + + db.commit() |