From c2bb49fec567c72f9752f99db783225787d87eb6 Mon Sep 17 00:00:00 2001 From: greens231 <1119231@gmail.com> Date: Wed, 6 Apr 2016 20:54:52 +0530 Subject: [PATCH] Fix 4e6a06bad7a8_init.py migration script to work with Postgres * Update 4e6a06bad7a8_init.py * removed comments --- .../migrations/versions/4e6a06bad7a8_init.py | 86 +++++++------------ 1 file changed, 29 insertions(+), 57 deletions(-) diff --git a/caravel/migrations/versions/4e6a06bad7a8_init.py b/caravel/migrations/versions/4e6a06bad7a8_init.py index 3b8a9bff452d1..9c8e2529afd88 100644 --- a/caravel/migrations/versions/4e6a06bad7a8_init.py +++ b/caravel/migrations/versions/4e6a06bad7a8_init.py @@ -28,10 +28,8 @@ def upgrade(): sa.Column('broker_port', sa.Integer(), nullable=True), sa.Column('broker_endpoint', sa.String(length=256), nullable=True), sa.Column('metadata_last_refreshed', sa.DateTime(), nullable=True), - sa.Column('created_by_fk', sa.Integer(), nullable=True), - sa.Column('changed_by_fk', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['changed_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['created_by_fk'], ['ab_user.id'], ), + sa.Column('created_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), + sa.Column('changed_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('cluster_name') ) @@ -41,10 +39,8 @@ def upgrade(): sa.Column('id', sa.Integer(), nullable=False), sa.Column('dashboard_title', sa.String(length=500), nullable=True), sa.Column('position_json', sa.Text(), nullable=True), - sa.Column('created_by_fk', sa.Integer(), nullable=True), - sa.Column('changed_by_fk', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['changed_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['created_by_fk'], ['ab_user.id'], ), + sa.Column('created_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), + sa.Column('changed_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_table('dbs', @@ -53,10 +49,8 @@ def upgrade(): sa.Column('id', sa.Integer(), nullable=False), sa.Column('database_name', sa.String(length=250), nullable=True), sa.Column('sqlalchemy_uri', sa.String(length=1024), nullable=True), - sa.Column('created_by_fk', sa.Integer(), nullable=True), - sa.Column('changed_by_fk', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['changed_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['created_by_fk'], ['ab_user.id'], ), + sa.Column('created_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), + sa.Column('changed_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('database_name') ) @@ -69,14 +63,10 @@ def upgrade(): sa.Column('is_hidden', sa.Boolean(), nullable=True), sa.Column('description', sa.Text(), nullable=True), sa.Column('default_endpoint', sa.Text(), nullable=True), - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('cluster_name', sa.String(length=250), nullable=True), - sa.Column('changed_by_fk', sa.Integer(), nullable=False), - sa.Column('created_by_fk', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['changed_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['cluster_name'], ['clusters.cluster_name'], ), - sa.ForeignKeyConstraint(['created_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['ab_user.id'], ), + sa.Column('user_id', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), + sa.Column('cluster_name', sa.String(length=250), sa.ForeignKey("clusters.cluster_name"), nullable=True), + sa.Column('created_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), + sa.Column('changed_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('datasource_name') ) @@ -87,12 +77,9 @@ def upgrade(): sa.Column('table_name', sa.String(length=250), nullable=True), sa.Column('main_dttm_col', sa.String(length=250), nullable=True), sa.Column('default_endpoint', sa.Text(), nullable=True), - sa.Column('database_id', sa.Integer(), nullable=False), - sa.Column('created_by_fk', sa.Integer(), nullable=True), - sa.Column('changed_by_fk', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['changed_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['created_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['database_id'], ['dbs.id'], ), + sa.Column('database_id', sa.Integer(), sa.ForeignKey("dbs.id"), nullable=False), + sa.Column('created_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), + sa.Column('changed_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('table_name') ) @@ -101,7 +88,7 @@ def upgrade(): sa.Column('changed_on', sa.DateTime(), nullable=False), sa.Column('id', sa.Integer(), nullable=False), sa.Column('datasource_name', sa.String(length=250), nullable=True), - sa.Column('column_name', sa.String(length=256), nullable=True), + sa.Column('column_name', sa.String(length=256), sa.ForeignKey("datasources.datasource_name"), nullable=True), sa.Column('is_active', sa.Boolean(), nullable=True), sa.Column('type', sa.String(length=32), nullable=True), sa.Column('groupby', sa.Boolean(), nullable=True), @@ -111,11 +98,8 @@ def upgrade(): sa.Column('min', sa.Boolean(), nullable=True), sa.Column('filterable', sa.Boolean(), nullable=True), sa.Column('description', sa.Text(), nullable=True), - sa.Column('created_by_fk', sa.Integer(), nullable=True), - sa.Column('changed_by_fk', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['changed_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['created_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['datasource_name'], ['datasources.datasource_name'], ), + sa.Column('created_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), + sa.Column('changed_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_table('metrics', @@ -123,7 +107,7 @@ def upgrade(): sa.Column('metric_name', sa.String(length=512), nullable=True), sa.Column('verbose_name', sa.String(length=1024), nullable=True), sa.Column('metric_type', sa.String(length=32), nullable=True), - sa.Column('datasource_name', sa.String(length=250), nullable=True), + sa.Column('datasource_name', sa.String(length=250), sa.ForeignKey("datasources.datasource_name"), nullable=True), sa.Column('json', sa.Text(), nullable=True), sa.Column('description', sa.Text(), nullable=True), sa.ForeignKeyConstraint(['datasource_name'], ['datasources.datasource_name'], ), @@ -134,18 +118,14 @@ def upgrade(): sa.Column('changed_on', sa.DateTime(), nullable=False), sa.Column('id', sa.Integer(), nullable=False), sa.Column('slice_name', sa.String(length=250), nullable=True), - sa.Column('druid_datasource_id', sa.Integer(), nullable=True), - sa.Column('table_id', sa.Integer(), nullable=True), + sa.Column('druid_datasource_id', sa.Integer(), sa.ForeignKey("datasources.id"), nullable=True), + sa.Column('table_id', sa.Integer(), sa.ForeignKey("tables.id"), nullable=True), sa.Column('datasource_type', sa.String(length=200), nullable=True), sa.Column('datasource_name', sa.String(length=2000), nullable=True), sa.Column('viz_type', sa.String(length=250), nullable=True), sa.Column('params', sa.Text(), nullable=True), - sa.Column('created_by_fk', sa.Integer(), nullable=True), - sa.Column('changed_by_fk', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['changed_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['created_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['druid_datasource_id'], ['datasources.id'], ), - sa.ForeignKeyConstraint(['table_id'], ['tables.id'], ), + sa.Column('created_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), + sa.Column('changed_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_table('sql_metrics', @@ -155,21 +135,18 @@ def upgrade(): sa.Column('metric_name', sa.String(length=512), nullable=True), sa.Column('verbose_name', sa.String(length=1024), nullable=True), sa.Column('metric_type', sa.String(length=32), nullable=True), - sa.Column('table_id', sa.Integer(), nullable=True), + sa.Column('table_id', sa.Integer(), sa.ForeignKey("tables.id"), nullable=True), sa.Column('expression', sa.Text(), nullable=True), sa.Column('description', sa.Text(), nullable=True), - sa.Column('created_by_fk', sa.Integer(), nullable=True), - sa.Column('changed_by_fk', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['changed_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['created_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['table_id'], ['tables.id'], ), + sa.Column('created_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), + sa.Column('changed_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_table('table_columns', sa.Column('created_on', sa.DateTime(), nullable=False), sa.Column('changed_on', sa.DateTime(), nullable=False), sa.Column('id', sa.Integer(), nullable=False), - sa.Column('table_id', sa.Integer(), nullable=True), + sa.Column('table_id', sa.Integer(), sa.ForeignKey("tables.id"), nullable=True), sa.Column('column_name', sa.String(length=256), nullable=True), sa.Column('is_dttm', sa.Boolean(), nullable=True), sa.Column('is_active', sa.Boolean(), nullable=True), @@ -181,19 +158,14 @@ def upgrade(): sa.Column('min', sa.Boolean(), nullable=True), sa.Column('filterable', sa.Boolean(), nullable=True), sa.Column('description', sa.Text(), nullable=True), - sa.Column('created_by_fk', sa.Integer(), nullable=True), - sa.Column('changed_by_fk', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['changed_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['created_by_fk'], ['ab_user.id'], ), - sa.ForeignKeyConstraint(['table_id'], ['tables.id'], ), + sa.Column('created_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), + sa.Column('changed_by_fk', sa.Integer(), sa.ForeignKey("ab_user.id"), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_table('dashboard_slices', sa.Column('id', sa.Integer(), nullable=False), - sa.Column('dashboard_id', sa.Integer(), nullable=True), - sa.Column('slice_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['dashboard_id'], ['dashboards.id'], ), - sa.ForeignKeyConstraint(['slice_id'], ['slices.id'], ), + sa.Column('dashboard_id', sa.Integer(), sa.ForeignKey("dashboards.id"), nullable=True), + sa.Column('slice_id', sa.Integer(), sa.ForeignKey("slices.id"), nullable=True), sa.PrimaryKeyConstraint('id') ) ### end Alembic commands ###