Merge "Fix migration set_length_of_description_field_metering"

This commit is contained in:
Jenkins 2014-08-25 10:13:01 +00:00 committed by Gerrit Code Review
commit cd7c6e6e71
2 changed files with 28 additions and 5 deletions

View File

@ -51,3 +51,18 @@ def alter_enum(table, column, enum_type, nullable):
else:
op.alter_column(table, column, type_=enum_type,
existing_nullable=nullable)
def create_table_if_not_exist_psql(table_name, values):
if op.get_bind().engine.dialect.server_version_info < (9, 1, 0):
op.execute("CREATE LANGUAGE plpgsql")
op.execute("CREATE OR REPLACE FUNCTION execute(TEXT) RETURNS VOID AS $$"
"BEGIN EXECUTE $1; END;"
"$$ LANGUAGE plpgsql STRICT;")
op.execute("CREATE OR REPLACE FUNCTION table_exist(TEXT) RETURNS bool as "
"$$ SELECT exists(select 1 from pg_class where relname=$1);"
"$$ language sql STRICT;")
op.execute("SELECT execute($$CREATE TABLE %(name)s %(columns)s $$) "
"WHERE NOT table_exist(%(name)r);" %
{'name': table_name,
'columns': values})

View File

@ -41,6 +41,14 @@ def upgrade(active_plugins=None, options=None):
if not migration.should_run(active_plugins, migration_for_plugins):
return
if op.get_bind().engine.dialect.name == 'postgresql':
migration.create_table_if_not_exist_psql(
'meteringlabels',
"(tenant_id VARCHAR(255) NULL, "
"id VARCHAR(36) PRIMARY KEY NOT NULL, "
"name VARCHAR(255) NULL, "
"description VARCHAR(255) NULL)")
else:
op.execute("CREATE TABLE IF NOT EXISTS meteringlabels( "
"tenant_id VARCHAR(255) NULL, "
"id VARCHAR(36) PRIMARY KEY NOT NULL, "