def upgrade(pyramid_env): from assembl import models as m from assembl.scripts.rebuild_tables import rebuild_table # These tables had a nullable changed in d5204c294082bfa97284fcec273e3f53a464db51 # except post was done in previous migration rebuild = [ 'partner_organization', 'agent_status_in_discussion', 'content_source', 'discussion_permission', 'anonymous_user', 'content_source_ids', 'imported_post', 'local_user_role', 'notification_subscription_on_extract', 'notification_subscription_on_idea', 'notification_subscription_on_post', 'notification_subscription_on_useraccount', 'sub_graph_idea_association', 'sub_graph_idea_link_association', # 'text_fragment_identifier', 'timeline_event', 'user_language_preference', 'user_role', 'user_template', 'username'] tables = m.get_metadata().sorted_tables tables.reverse() for table in tables: if table.name in rebuild: rebuild_table(table, True)
def downgrade(pyramid_env): from assembl.semantic.virtuoso_mapping import get_session from assembl.models import Content assert not ('body' in Content.__table__.c or 'subject' in Content.__table__.c), \ "Comment out the body and subject from Content to run the back migration" dbsession = get_session() try: dbsession.execute("SPARQL drop quad map quadnames:col_pattern_Content_subject") dbsession.commit() except: dbsession.rollback() op.add_column('post', sa.Column('subject', sa.Unicode, server_default="")) op.add_column('post', sa.Column('body', sa.UnicodeText, server_default="")) with context.begin_transaction(): op.execute( """UPDATE post SET subject = ( SELECT subject FROM content WHERE post.id = content.id) """) op.execute( """UPDATE post SET body = ( SELECT body FROM content WHERE content.id = post.id AND content.body IS NOT NULL) """) from assembl.scripts.rebuild_tables import rebuild_table rebuild_table(Content.__table__, True)
def upgrade(pyramid_env): from assembl import models as m from assembl.scripts.rebuild_tables import rebuild_table from assembl.semantic.virtuoso_mapping import AppQuadStorageManager aqsm = AppQuadStorageManager() aqsm.drop_all() # These tables had a nullable changed in d5204c294082bfa97284fcec273e3f53a464db51 # except post was done in previous migration rebuild = [ 'partner_organization', 'agent_status_in_discussion', 'content_source', 'discussion_permission', 'anonymous_user', 'content_source_ids', 'imported_post', 'local_user_role', 'notification_subscription_on_extract', 'notification_subscription_on_idea', 'notification_subscription_on_post', 'notification_subscription_on_useraccount', 'sub_graph_idea_association', 'sub_graph_idea_link_association', # 'text_fragment_identifier', 'timeline_event', 'user_language_preference', 'user_role', 'user_template', 'username'] tables = m.get_metadata().sorted_tables tables.reverse() for table in tables: if table.name in rebuild: rebuild_table(table, True)
def downgrade(pyramid_env): from assembl.semantic.virtuoso_mapping import get_session from assembl.models import Content assert not ('body' in Content.__table__.c or 'subject' in Content.__table__.c), \ "Comment out the body and subject from Content to run the back migration" dbsession = get_session() try: dbsession.execute( "SPARQL drop quad map quadnames:col_pattern_Content_subject") dbsession.commit() except: dbsession.rollback() op.add_column('post', sa.Column('subject', sa.Unicode, server_default="")) op.add_column('post', sa.Column('body', sa.UnicodeText, server_default="")) with context.begin_transaction(): op.execute("""UPDATE post SET subject = ( SELECT subject FROM content WHERE post.id = content.id) """) op.execute("""UPDATE post SET body = ( SELECT body FROM content WHERE content.id = post.id AND content.body IS NOT NULL) """) from assembl.scripts.rebuild_tables import rebuild_table rebuild_table(Content.__table__, True)
def upgrade(pyramid_env): from assembl.semantic.virtuoso_mapping import get_session dbsession = get_session() dbsession.execute( "SPARQL drop quad map quadnames:col_pattern_Post_subject") dbsession.commit() with context.begin_transaction(): op.add_column('content', sa.Column('subject', sa.Unicode, server_default="")) op.add_column('content', sa.Column('body', sa.UnicodeText, server_default="")) with context.begin_transaction(): op.execute("""UPDATE content SET subject = ( SELECT subject FROM post WHERE post.id = content.id) """) op.execute("""UPDATE content SET body = ( SELECT body FROM post WHERE post.id = content.id) """) from assembl.scripts.rebuild_tables import rebuild_table from assembl.models import Post # Thanks to https://github.com/openlink/virtuoso-opensource/issues/378 # The aim is to remove the columns from the table; make sure they are not in the model when you migrate rebuild_table(Post.__table__, True)
def downgrade(pyramid_env): from assembl.models import Content assert not ('body' in Content.__table__.c or 'subject' in Content.__table__.c), \ "Comment out the body and subject from Content to run the back migration" op.add_column('post', sa.Column('subject', sa.Unicode, server_default="")) op.add_column('post', sa.Column('body', sa.UnicodeText, server_default="")) with context.begin_transaction(): op.execute("""UPDATE post SET subject = ( SELECT subject FROM content WHERE post.id = content.id) """) op.execute("""UPDATE post SET body = ( SELECT body FROM content WHERE content.id = post.id AND content.body IS NOT NULL) """) from assembl.scripts.rebuild_tables import rebuild_table rebuild_table(Content.__table__, True)
def upgrade(pyramid_env): from assembl.semantic.virtuoso_mapping import get_session dbsession = get_session() dbsession.execute("SPARQL drop quad map quadnames:col_pattern_Post_subject") dbsession.commit() with context.begin_transaction(): op.add_column('content', sa.Column('subject', sa.Unicode, server_default="")) op.add_column('content', sa.Column('body', sa.UnicodeText, server_default="")) with context.begin_transaction(): op.execute( """UPDATE content SET subject = ( SELECT subject FROM post WHERE post.id = content.id) """) op.execute( """UPDATE content SET body = ( SELECT body FROM post WHERE post.id = content.id) """) from assembl.scripts.rebuild_tables import rebuild_table from assembl.models import Post # Thanks to https://github.com/openlink/virtuoso-opensource/issues/378 # The aim is to remove the columns from the table; make sure they are not in the model when you migrate rebuild_table(Post.__table__, True)