Skip to content

Instantly share code, notes, and snippets.

@zidarsk8
Created November 13, 2017 12:34
Show Gist options
  • Save zidarsk8/8d40ecd9fdc25634719d30c209d788a4 to your computer and use it in GitHub Desktop.
Save zidarsk8/8d40ecd9fdc25634719d30c209d788a4 to your computer and use it in GitHub Desktop.
$ git diff
diff --git a/src/ggrc/migrations/versions/20171110090511_4b9a43e7b623_fix_notes_data.py b/src/ggrc/migrations/versions/20171110090511_4b9a43e7b623_fix_notes_data.py
index 0641cdf12..fdec05214 100644
--- a/src/ggrc/migrations/versions/20171110090511_4b9a43e7b623_fix_notes_data.py
+++ b/src/ggrc/migrations/versions/20171110090511_4b9a43e7b623_fix_notes_data.py
@@ -18,6 +18,11 @@ revision = '4b9a43e7b623'
down_revision = '33d043d8ba29'
+IGNORE_TABLES = {
+ "custom_attribute_definitions",
+}
+
+
def upgrade():
"""Upgrade database schema and/or data, creating a new revision."""
connection = op.get_bind()
@@ -30,8 +35,12 @@ def upgrade():
""")
query = "UPDATE {table_name} SET {col_name}='' WHERE {col_name} IS NULL;"
for table_name, col_name in results:
+ if table_name in IGNORE_TABLES:
+ continue
+ print "Removing null values from: {} - {}".format(table_name, col_name)
connection.execute(query.format(table_name=table_name,
col_name=col_name))
+ print "Setting filed to non-nullable: {} - {}".format(table_name, col_name)
op.alter_column(table_name, col_name, nullable=False,
existing_type=sa.Text())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment