from sqlalchemy import *
from migrate import *
from migrate.changeset import *

from raggregate.guid_recipe import GUID

meta = MetaData()

# this ugly table generated by Submission.__table__ and manually made usable.
gen_table = Table('submissions', meta, Column('id', GUID(),  primary_key=True, nullable=False), Column('title', UnicodeText(),  nullable=False), Column('description', UnicodeText(), ), Column('points', Integer(), ), Column('comment_tally', Integer(), ), Column('category', GUID(), ), Column('url', UnicodeText(), ), Column('self_post', Boolean(), ), Column('added_on', DateTime(timezone=True),  default=ColumnDefault(func.now())), Column('added_by', GUID(), ForeignKey('users.id'),  nullable=False), Column('deleted', Boolean(),  default=ColumnDefault(False)), Column('invisible', Boolean(),  default=ColumnDefault(False)), Column('hot_window_score', Integer(), ), Column('hot_window_score_timestamp', DateTime(timezone=True), ), Column('downvote_tally', Integer(), ), Column('downvote_tally_timestamp', DateTime(timezone=True), ), Column('upvote_tally', Integer(), ), Column('upvote_tally_timestamp', DateTime(timezone=True), ), Column('total_vote_tally', Integer(), ), Column('total_vote_timestamp', DateTime(timezone=True), ),)

def upgrade(migrate_engine):
    meta.bind = migrate_engine
    for col in gen_table.c:
        # modify all DateTime columns to tz awareness
        if type(col.type) == DateTime:
            col.alter(type = DateTime(timezone=True))

def downgrade(migrate_engine):
    meta.bind = migrate_engine
    for col in gen_table.c:
        # modify all DateTime columns to tz naivety
        if type(col.type) == DateTime:
            col.alter(type = DateTime(timezone=False))

@@ -118,1134 +118,598 @@
 ID%0A%0A
-meta = MetaData()%0A%0A# this ugly table generated by Submission.__table__ and manually made usable.%0Agen_table = Table('submissions', meta, Column('id', GUID(),  primary_key=True, nullable=False), Column('title', UnicodeText(),  nullable=False), Column('description', UnicodeText(), ), Column('points', Integer(), ), Column('comment_tally', Integer(), ), Column('category', GUID(), ), Column('url', UnicodeText(), ), Column('self_post', Boolean(), ), Column('added_on', DateTime(timezone=True),  default=ColumnDefault(func.now())), Column('added_by', GUID(), ForeignKey('users.id'),  nullable=False), Column('deleted', Boolean(),  default=ColumnD
+# referring to the models directly, this is %22very bad%22 and sqlalchemy-migrate%0A# docs will yell at you extensively for doing it. OH well, much easier this way%0A# for the time being, and this migration is pretty basic so it shouldn't cause%0A# problems down the road (hop
 ef
-a
 ul
-t(False)), Column('invisible', Boolean(),  default=ColumnDefault(False)), Column('hot_window_score', Integer(), ), Column('hot_window_score_timestamp', DateTime(timezone=True), ), Column('downvote_tally', Integer(), ), Column('downvote_tally_timestamp', DateTime(timezone=True), ), Column('upvote_tally', Integer(), ), Column('upvote_tally_timestamp', DateTime(timezone=True), )
+ly).%0A%0Afrom raggregate.models import Submission%0Afrom raggregate.models import User%0Afrom raggregate.models import Comment%0Afrom raggregate.models import Vote%0Afrom raggregate.models import Epistle%0Afrom raggregate.models import Stat%0A%0Amodel_list = %5B'Submission', 'User'
 , 
+'
 Co
-lumn('total_vote_tally', Integer(), ), Column('total_vote_timestamp', DateTime(timezone=True), ),
+mment', 'Vote', 'Epistle', 'Stat'%5D%0A%0Ameta = MetaData(
 )%0A%0Ad
@@ -775,36 +775,117 @@
     for 
-col
+m
  in 
-gen_table.c:%0A
+model_list:%0A        t = eval(m).__table__%0A        t.metadata = meta%0A        for col in t.c:%0A    
         
@@ -930,32 +930,36 @@
 areness%0A        
+    
 if type(col.type
@@ -965,32 +965,36 @@
 e) == DateTime:%0A
+    
             col.
@@ -1106,24 +1106,101 @@
 for 
-col
+m
  in 
-gen_table
+model_list:%0A        t = eval(m).__table__%0A        t.metadata = meta%0A        for col in t
 .c:%0A
@@ -1199,32 +1199,36 @@
 in t.c:%0A        
+   
+ 
 # modify all Dat
@@ -1251,16 +1251,22 @@
  tz 
-naivety%0A
+awareness%0A    
     
@@ -1292,32 +1292,36 @@
 e) == DateTime:%0A
+    
             col.

Fix migration to automatically load and update all tables. ...