def upgrade(): connection = op.get_bind() proposal_space = table('proposal_space', column(u'id', sa.INTEGER()), column(u'description_text', sa.TEXT()), column(u'description_html', sa.TEXT()), column(u'content', JsonDict())) results = connection.execute(proposal_space.select()) for space in results: if space['content']: for (section, title) in [ ('format', u"Format"), ('criteria', u"Criteria for proposals"), ('panel', u"Editorial panel"), ('dates', u"Important dates"), ('open_source', u"Commitment to Open Source"), ('themes', u"Theme") ]: modified = False text = space['description_text'] if space['content'].get(section): modified = True text = text + '\r\n\r\n' + u"## " + title + '\r\n\r\n' + space['content'][section] if modified: html = markdown(text) connection.execute( proposal_space.update().where( proposal_space.c.id == space['id']).values( {'description_text': text, 'description_html': html, 'content': {}}))
def upgrade(): ### commands auto generated by Alembic - please adjust! ### op.create_table( 'user', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('status', sa.Integer(), nullable=False), sa.Column('lastuser_token_scope', sa.Unicode(length=250), nullable=True), sa.Column('lastuser_token_type', sa.Unicode(length=250), nullable=True), sa.Column('userinfo', JsonDict(), nullable=True), sa.Column('email', sa.Unicode(length=80), nullable=True), sa.Column('lastuser_token', sa.String(length=22), nullable=True), sa.Column('username', sa.Unicode(length=80), nullable=True), sa.Column('userid', sa.String(length=22), nullable=False), sa.Column('fullname', sa.Unicode(length=80), nullable=False), sa.Column('id', sa.Integer(), nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('email'), sa.UniqueConstraint('lastuser_token'), sa.UniqueConstraint('userid'), sa.UniqueConstraint('username')) op.create_table('post', sa.Column('id', sa.Integer(), nullable=False), sa.Column('body', sa.String(length=140), nullable=True), sa.Column('timestamp', sa.DateTime(), nullable=True), sa.Column('user_id', sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id'))
def upgrade(): op.create_table( 'campaign_anon_view', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('campaign_id', sa.Integer(), nullable=False), sa.Column('anon_user_id', sa.Integer(), nullable=False), sa.Column('dismissed', sa.Boolean(), nullable=False), sa.Column('session_count', sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ['anon_user_id'], ['anon_user.id'], ), sa.ForeignKeyConstraint( ['campaign_id'], ['campaign.id'], ), sa.PrimaryKeyConstraint('campaign_id', 'anon_user_id')) op.create_index(op.f('ix_campaign_anon_view_anon_user_id'), 'campaign_anon_view', ['anon_user_id'], unique=False) op.create_table( 'campaign_event_session', sa.Column('campaign_id', sa.Integer(), nullable=False), sa.Column('event_session_id', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=True), sa.ForeignKeyConstraint( ['campaign_id'], ['campaign.id'], ), sa.ForeignKeyConstraint( ['event_session_id'], ['event_session.id'], ), sa.PrimaryKeyConstraint('campaign_id', 'event_session_id')) op.create_index(op.f('ix_campaign_event_session_event_session_id'), 'campaign_event_session', ['event_session_id'], unique=False) op.create_table( 'campaign_anon_user_action', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('action_id', sa.Integer(), nullable=False), sa.Column('anon_user_id', sa.Integer(), nullable=False), sa.Column('ipaddr', sa.String(length=45), nullable=True), sa.Column('useragent', sa.Unicode(length=250), nullable=True), sa.Column('data', JsonDict(), server_default='{}', nullable=False), sa.ForeignKeyConstraint( ['action_id'], ['campaign_action.id'], ), sa.ForeignKeyConstraint( ['anon_user_id'], ['anon_user.id'], ), sa.PrimaryKeyConstraint('action_id', 'anon_user_id')) op.create_index(op.f('ix_campaign_anon_user_action_anon_user_id'), 'campaign_anon_user_action', ['anon_user_id'], unique=False) op.add_column( 'campaign_view', sa.Column('session_count', sa.Integer(), nullable=False, server_default=sa.text('0'))) op.alter_column('campaign_view', 'session_count', server_default=None)
def upgrade(): op.create_table('anon_user', sa.Column('id', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id')) op.create_index(op.f('ix_anon_user_user_id'), 'anon_user', ['user_id'], unique=False) op.create_table( 'event_session', sa.Column('id', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=True), sa.Column('anon_user_id', sa.Integer(), nullable=True), sa.Column('referrer', sa.Unicode(length=2083), nullable=True), sa.Column('utm_source', sa.Unicode(length=250), nullable=False), sa.Column('utm_medium', sa.Unicode(length=250), nullable=False), sa.Column('utm_term', sa.Unicode(length=250), nullable=False), sa.Column('utm_content', sa.Unicode(length=250), nullable=False), sa.Column('utm_id', sa.Unicode(length=250), nullable=False), sa.Column('utm_campaign', sa.Unicode(length=250), nullable=False), sa.Column('gclid', sa.Unicode(length=250), nullable=False), sa.Column('active_at', sa.DateTime(), nullable=False), sa.Column('ended_at', sa.DateTime(), nullable=True), sa.CheckConstraint( u'CASE WHEN (event_session.user_id IS NOT NULL) THEN 1 ELSE 0 END + CASE WHEN (event_session.anon_user_id IS NOT NULL) THEN 1 ELSE 0 END = 1', name='user_event_session_user_id_or_anon_user_id'), sa.ForeignKeyConstraint( ['anon_user_id'], ['anon_user.id'], ), sa.ForeignKeyConstraint( ['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id')) op.create_index(op.f('ix_event_session_anon_user_id'), 'event_session', ['anon_user_id'], unique=False) op.create_index(op.f('ix_event_session_user_id'), 'event_session', ['user_id'], unique=False) op.create_table( 'user_event', sa.Column('id', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('event_session_id', sa.Integer(), nullable=False), sa.Column('url', sa.Unicode(length=2038), nullable=True), sa.Column('referrer', sa.Unicode(length=2038), nullable=True), sa.Column('method', sa.Unicode(length=10), nullable=True), sa.Column('status_code', sa.SmallInteger(), nullable=True), sa.Column('name', sa.Unicode(length=80), nullable=False), sa.Column('data', JsonDict(), nullable=True), sa.ForeignKeyConstraint( ['event_session_id'], ['event_session.id'], ), sa.PrimaryKeyConstraint('id'))
def upgrade(): op.add_column( 'user', sa.Column('resume', JsonDict(), nullable=False, server_default=sa.text("'{}'"))) op.alter_column('user', 'resume', server_default=None)
def upgrade(): proposal_space = table('proposal_space', column('labels')) op.add_column( u'proposal_space', sa.Column('labels', JsonDict(), server_default='{}', nullable=False)) op.execute(proposal_space.update().values({ 'labels': '{"proposal": {"part_a": {"title": "Objective", "hint": "What is the expected benefit for someone attending this?"}, "part_b": {"title": "Description", "hint": "A detailed description of the session."}}}' }))
def upgrade(): op.add_column( 'proposal', sa.Column('data', JsonDict(), server_default='{}', nullable=False)) op.add_column('proposal', sa.Column('latitude', sa.Numeric(), nullable=True)) op.add_column('proposal', sa.Column('longitude', sa.Numeric(), nullable=True))
def upgrade(): op.create_table('job_location', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('jobpost_id', sa.Integer(), nullable=False), sa.Column('geonameid', sa.Integer(), nullable=False), sa.Column('primary', sa.Boolean(), nullable=False), sa.ForeignKeyConstraint(['jobpost_id'], ['jobpost.id'], ), sa.PrimaryKeyConstraint('jobpost_id', 'geonameid') ) op.add_column('jobpost', sa.Column('parsed_location', JsonDict(), nullable=True))
def downgrade(): op.add_column( 'proposal', sa.Column( 'data', JsonDict(), server_default=sa.text("'{}'"), autoincrement=False, nullable=False, ), )
def upgrade(): op.create_table( 'assignee', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('fullname', sa.Unicode(length=80), nullable=False), sa.Column('email', sa.Unicode(length=254), nullable=False), sa.Column('phone', sa.Unicode(length=16), nullable=True), sa.Column('details', JsonDict(), nullable=False), sa.Column('previous_id', sa.Integer(), nullable=True), sa.Column('user_id', sa.Integer(), nullable=True), sa.Column('id', sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ['previous_id'], ['assignee.id'], ), sa.ForeignKeyConstraint( ['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id'), ) op.add_column('line_item', sa.Column('assignee_id', sa.Integer(), nullable=True)) op.add_column( 'item', sa.Column('assignee_details', JsonDict(), server_default='{}', nullable=True), ) op.alter_column('item', 'assignee_details', server_default=None) op.create_foreign_key('line_item_assignee_id_fkey', 'line_item', 'assignee', ['assignee_id'], ['id']) op.create_index(op.f('assignee_email_key'), 'assignee', ['email'], unique=True)
def upgrade(): op.add_column( 'profile', sa.Column('logo_url', sa.Unicode(length=2000), nullable=True) ) op.add_column( 'project', sa.Column('banner_video_url', sa.Unicode(length=2000), nullable=True) ) op.add_column( 'project', sa.Column('boxoffice_data', JsonDict(), server_default='{}', nullable=False), ) op.add_column( 'project', sa.Column('hasjob_embed_limit', sa.Integer(), nullable=True) ) op.add_column( 'project', sa.Column('hasjob_embed_url', sa.Unicode(length=2000), nullable=True) )
def downgrade(): op.alter_column('user', 'userinfo', type_=sa.TEXT(), existing_type=JsonDict()) op.execute(CreateSequence(Sequence('proposal_redirect_url_id_seq'))) op.execute( sa.DDL( 'ALTER SEQUENCE proposal_redirect_url_id_seq OWNED BY proposal_redirect.url_id;' )) op.execute( sa.DDL( "ALTER TABLE ONLY proposal_redirect ALTER COLUMN url_id SET DEFAULT nextval('proposal_redirect_url_id_seq'::regclass);" )) # RENAME CONSTRAINT works in PostgreSQL >= 9.2 op.execute( sa.DDL( 'ALTER TABLE proposal_space RENAME CONSTRAINT proposal_space_parent_space_id_fkey TO proposal_space_proposal_space_id_fkey;' )) op.execute( sa.DDL( 'ALTER TABLE contact_exchange RENAME CONSTRAINT contact_exchange_pkey TO contact_exchange_user_id_proposal_space_id_participant_id_key;' )) op.execute( sa.DDL( 'ALTER TABLE rsvp RENAME CONSTRAINT rsvp_status_check TO ck_rsvp_state_valid;' )) op.execute( sa.DDL( 'ALTER TABLE proposal_space RENAME CONSTRAINT proposal_space_status_check TO ck_proposal_space_state_valid;' )) op.execute( sa.DDL( 'ALTER TABLE proposal RENAME CONSTRAINT proposal_status_check TO ck_proposal_state_valid;' )) op.execute( sa.DDL( 'ALTER TABLE comment RENAME CONSTRAINT comment_status_check TO ck_comment_state_valid;' )) for tablename in tables_with_name_column: # Drop CHECK constraint on name op.drop_constraint(tablename + '_name_check', tablename)
def upgrade(): for tablename in tables_with_name_column: # Create CHECK constraint on name op.create_check_constraint(tablename + '_name_check', tablename, "name <> ''") # RENAME CONSTRAINT works in PostgreSQL >= 9.2 op.execute( sa.DDL( 'ALTER TABLE comment RENAME CONSTRAINT ck_comment_state_valid TO comment_status_check;' )) op.execute( sa.DDL( 'ALTER TABLE proposal RENAME CONSTRAINT ck_proposal_state_valid TO proposal_status_check;' )) op.execute( sa.DDL( 'ALTER TABLE proposal_space RENAME CONSTRAINT ck_proposal_space_state_valid TO proposal_space_status_check;' )) op.execute( sa.DDL( 'ALTER TABLE rsvp RENAME CONSTRAINT ck_rsvp_state_valid TO rsvp_status_check;' )) op.execute( sa.DDL( 'ALTER TABLE contact_exchange RENAME CONSTRAINT contact_exchange_user_id_proposal_space_id_participant_id_key TO contact_exchange_pkey;' )) op.execute( sa.DDL( 'ALTER TABLE proposal_space RENAME CONSTRAINT proposal_space_proposal_space_id_fkey TO proposal_space_parent_space_id_fkey;' )) op.alter_column('proposal_redirect', 'url_id', existing_type=sa.INTEGER(), server_default=None) op.execute(DropSequence(Sequence('proposal_redirect_url_id_seq'))) op.alter_column( 'user', 'userinfo', type_=JsonDict(), existing_type=sa.TEXT(), postgresql_using='userinfo::jsonb', )
def upgrade(): op.create_table( 'project_location', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('project_id', sa.Integer(), nullable=False), sa.Column('geonameid', sa.Integer(), nullable=False), sa.Column('primary', sa.Boolean(), nullable=False), sa.ForeignKeyConstraint(['project_id'], ['project.id']), sa.PrimaryKeyConstraint('project_id', 'geonameid'), ) op.create_index( op.f('ix_project_location_geonameid'), 'project_location', ['geonameid'], unique=False, ) op.add_column( 'project', sa.Column('location', sa.Unicode(length=50), nullable=True) ) op.add_column( 'project', sa.Column('parsed_location', JsonDict(), server_default='{}', nullable=False), )
def upgrade(): op.create_table( 'campaign', sa.Column('id', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('start_at', sa.DateTime(), nullable=False), sa.Column('end_at', sa.DateTime(), nullable=False), sa.Column('public', sa.Boolean(), nullable=False), sa.Column('position', sa.SmallInteger(), nullable=False), sa.Column('priority', sa.Integer(), nullable=False), sa.Column('subject', sa.Unicode(length=250), nullable=True), sa.Column('blurb', sa.UnicodeText(), nullable=False), sa.Column('description', sa.UnicodeText(), nullable=False), sa.Column('banner_image', sa.Unicode(length=250), nullable=True), sa.Column('banner_location', sa.SmallInteger(), nullable=False), sa.Column('name', sa.Unicode(length=250), nullable=False), sa.Column('title', sa.Unicode(length=250), nullable=False), sa.ForeignKeyConstraint( ['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name')) op.create_table( 'campaign_board', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('board_id', sa.Integer(), nullable=False), sa.Column('campaign_id', sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ['board_id'], ['board.id'], ), sa.ForeignKeyConstraint( ['campaign_id'], ['campaign.id'], ), sa.PrimaryKeyConstraint('board_id', 'campaign_id')) op.create_index(op.f('ix_campaign_board_campaign_id'), 'campaign_board', ['campaign_id'], unique=False) op.create_table( 'campaign_view', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('campaign_id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ['campaign_id'], ['campaign.id'], ), sa.ForeignKeyConstraint( ['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('campaign_id', 'user_id')) op.create_table( 'campaign_location', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('campaign_id', sa.Integer(), nullable=False), sa.Column('geonameid', sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ['campaign_id'], ['campaign.id'], ), sa.PrimaryKeyConstraint('campaign_id', 'geonameid')) op.create_index(op.f('ix_campaign_location_geonameid'), 'campaign_location', ['geonameid'], unique=False) op.create_table( 'campaign_action', sa.Column('id', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('campaign_id', sa.Integer(), nullable=False), sa.Column('public', sa.Boolean(), nullable=False), sa.Column('type', sa.Enum('D', 'F', 'L', 'M', 'N', 'Y', name='campaign_action_type_enum'), nullable=False), sa.Column('category', sa.Unicode(length=20), nullable=False), sa.Column('link', sa.Unicode(length=250), nullable=True), sa.Column('form', JsonDict(), nullable=False), sa.Column('name', sa.Unicode(length=250), nullable=False), sa.Column('title', sa.Unicode(length=250), nullable=False), sa.ForeignKeyConstraint( ['campaign_id'], ['campaign.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('campaign_id', 'name')) op.create_table( 'campaign_user_action', sa.Column('id', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('action_id', sa.Integer(), nullable=True), sa.Column('user_id', sa.Integer(), nullable=True), sa.Column('ipaddr', sa.String(length=45), nullable=True), sa.Column('useragent', sa.Unicode(length=250), nullable=True), sa.Column('data', JsonDict(), nullable=False), sa.ForeignKeyConstraint( ['action_id'], ['campaign_action.id'], ), sa.ForeignKeyConstraint( ['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id')) op.create_index(op.f('ix_campaign_user_action_action_id'), 'campaign_user_action', ['action_id'], unique=False) op.create_index(op.f('ix_campaign_user_action_user_id'), 'campaign_user_action', ['user_id'], unique=False) op.create_index(op.f('ix_userjobview_user_id'), 'userjobview', ['user_id'], unique=False)
def upgrade(): op.create_table( 'organization', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('userid', sa.Unicode(length=22), nullable=False), sa.Column('status', sa.Integer(), nullable=False), sa.Column('name', sa.Unicode(length=250), nullable=False), sa.Column('title', sa.Unicode(length=250), nullable=False), sa.Column('details', JsonDict(), server_default='{}', nullable=False), sa.Column('id', sa.Integer(), nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name'), sa.UniqueConstraint('userid')) op.create_table( 'user', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('status', sa.Integer(), nullable=False), sa.Column('lastuser_token_scope', sa.Unicode(length=250), nullable=True), sa.Column('lastuser_token_type', sa.Unicode(length=250), nullable=True), sa.Column('userinfo', coaster.sqlalchemy.JsonDict(), nullable=True), sa.Column('email', sa.Unicode(length=80), nullable=True), sa.Column('lastuser_token', sa.String(length=22), nullable=True), sa.Column('username', sa.Unicode(length=80), nullable=True), sa.Column('userid', sa.String(length=22), nullable=False), sa.Column('fullname', sa.Unicode(length=80), nullable=False), sa.Column('id', sa.Integer(), nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('email'), sa.UniqueConstraint('lastuser_token'), sa.UniqueConstraint('userid'), sa.UniqueConstraint('username')) op.create_table( 'discount_policy', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('organization_id', sa.Integer(), nullable=False), sa.Column('discount_type', sa.Integer(), nullable=False), sa.Column('item_quantity_min', sa.Integer(), nullable=False), sa.Column('item_quantity_max', sa.Integer(), nullable=True), sa.Column('discount_code_base', sa.Unicode(length=20), nullable=True), sa.Column('percentage', sa.Integer(), nullable=False), sa.Column('name', sa.Unicode(length=250), nullable=False), sa.Column('title', sa.Unicode(length=250), nullable=False), sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.CheckConstraint(u'item_quantity_min <= item_quantity_max', name='discount_policy_item_quantity_check'), sa.CheckConstraint(u'percentage > 0 and percentage <= 100', name='discount_policy_percentage_check'), sa.ForeignKeyConstraint( ['organization_id'], ['organization.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('organization_id', 'name')) op.create_table( 'item_collection', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('description_text', sa.UnicodeText(), nullable=False), sa.Column('description_html', sa.UnicodeText(), nullable=False), sa.Column('organization_id', sa.Integer(), nullable=False), sa.Column('name', sa.Unicode(length=250), nullable=False), sa.Column('title', sa.Unicode(length=250), nullable=False), sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.ForeignKeyConstraint( ['organization_id'], ['organization.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('organization_id', 'name')) op.create_table( 'category', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('item_collection_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column('name', sa.Unicode(length=250), nullable=False), sa.Column('title', sa.Unicode(length=250), nullable=False), sa.Column('id', sa.Integer(), nullable=False), sa.Column('seq', sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ['item_collection_id'], ['item_collection.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('item_collection_id', 'name'), sa.UniqueConstraint('item_collection_id', 'seq')) op.create_table( 'customer_order', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=True), sa.Column('organization_id', sa.Integer(), nullable=False), sa.Column('item_collection_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column('status', sa.Integer(), nullable=False), sa.Column('initiated_at', sa.DateTime(), nullable=False), sa.Column('paid_at', sa.DateTime(), nullable=True), sa.Column('invoiced_at', sa.DateTime(), nullable=True), sa.Column('cancelled_at', sa.DateTime(), nullable=True), sa.Column('access_token', sa.Unicode(length=22), nullable=False), sa.Column('buyer_email', sa.Unicode(length=254), nullable=False), sa.Column('buyer_fullname', sa.Unicode(length=80), nullable=False), sa.Column('buyer_phone', sa.Unicode(length=16), nullable=False), sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column('invoice_no', sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ['organization_id'], ['organization.id'], ), sa.ForeignKeyConstraint( ['item_collection_id'], ['item_collection.id'], ), sa.ForeignKeyConstraint( ['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('organization_id', 'invoice_no')) op.create_table( 'discount_coupon', sa.Column('code', sa.Unicode(length=20), nullable=False), sa.Column('discount_policy_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column('quantity_available', sa.Integer(), nullable=False), sa.Column('quantity_total', sa.Integer(), nullable=False), sa.Column('used_at', sa.DateTime(), nullable=True), sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.CheckConstraint(u'quantity_available <= quantity_total', name='discount_coupon_quantity_check'), sa.ForeignKeyConstraint( ['discount_policy_id'], ['discount_policy.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('discount_policy_id', 'code')) op.create_table( 'item', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('description_text', sa.UnicodeText(), nullable=False), sa.Column('description_html', sa.UnicodeText(), nullable=False), sa.Column('item_collection_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column('category_id', sa.Integer(), nullable=False), sa.Column('quantity_available', sa.Integer(), nullable=False), sa.Column('quantity_total', sa.Integer(), nullable=False), sa.Column('name', sa.Unicode(length=250), nullable=False), sa.Column('title', sa.Unicode(length=250), nullable=False), sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.ForeignKeyConstraint( ['category_id'], ['category.id'], ), sa.ForeignKeyConstraint( ['item_collection_id'], ['item_collection.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('item_collection_id', 'name'), sa.CheckConstraint( u'quantity_available <= quantity_total', name='item_quantity_available_lte_quantity_total_check')) op.create_table( 'online_payment', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('customer_order_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column('pg_paymentid', sa.Unicode(length=80), nullable=False), sa.Column('pg_payment_status', sa.Integer(), nullable=False), sa.Column('confirmed_at', sa.DateTime(), nullable=True), sa.Column('failed_at', sa.DateTime(), nullable=True), sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.ForeignKeyConstraint( ['customer_order_id'], ['customer_order.id'], ), sa.PrimaryKeyConstraint('id')) op.create_table( 'item_discount_policy', sa.Column('item_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column('discount_policy_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa.ForeignKeyConstraint( ['discount_policy_id'], ['discount_policy.id'], ), sa.ForeignKeyConstraint( ['item_id'], ['item.id'], ), sa.PrimaryKeyConstraint('item_id', 'discount_policy_id')) op.create_table( 'line_item', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('customer_order_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column('item_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column('discount_policy_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=True), sa.Column('discount_coupon_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=True), sa.Column('base_amount', sa.Numeric(), nullable=False), sa.Column('discounted_amount', sa.Numeric(), nullable=False), sa.Column('final_amount', sa.Numeric(), nullable=False), sa.Column('status', sa.Integer(), nullable=False), sa.Column('ordered_at', sa.DateTime(), nullable=True), sa.Column('cancelled_at', sa.DateTime(), nullable=True), sa.Column('line_item_seq', sa.Integer(), nullable=False), sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.ForeignKeyConstraint( ['customer_order_id'], ['customer_order.id'], ), sa.ForeignKeyConstraint( ['discount_policy_id'], ['discount_policy.id'], ), sa.ForeignKeyConstraint( ['discount_coupon_id'], ['discount_coupon.id'], ), sa.ForeignKeyConstraint( ['item_id'], ['item.id'], ), sa.UniqueConstraint('customer_order_id', 'line_item_seq'), sa.PrimaryKeyConstraint('id')) op.create_table( 'payment_transaction', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('customer_order_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column('online_payment_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=True), sa.Column('amount', sa.Numeric(), nullable=False), sa.Column('currency', sa.Unicode(length=3), nullable=False), sa.Column('transaction_type', sa.Integer(), nullable=False), sa.Column('transaction_method', sa.Integer(), nullable=False), sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.ForeignKeyConstraint( ['customer_order_id'], ['customer_order.id'], ), sa.ForeignKeyConstraint( ['online_payment_id'], ['online_payment.id'], ), sa.PrimaryKeyConstraint('id')) op.create_table( 'price', sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('updated_at', sa.DateTime(), nullable=False), sa.Column('item_id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.Column('start_at', sa.DateTime(), nullable=False), sa.Column('end_at', sa.DateTime(), nullable=False), sa.Column('amount', sa.Numeric(), nullable=False), sa.Column('currency', sa.Unicode(length=3), nullable=False), sa.Column('name', sa.Unicode(length=250), nullable=False), sa.Column('title', sa.Unicode(length=250), nullable=False), sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(), nullable=False), sa.ForeignKeyConstraint( ['item_id'], ['item.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('item_id', 'name'), sa.CheckConstraint(u'start_at < end_at', name='price_start_at_lt_end_at_check'))