We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
IntegrityError: (psycopg2.IntegrityError) null value in column "name" violates not-null constraint
https://sentry.eventyay.com/eventyay/api/issues/14/

```
IntegrityError: (psycopg2.IntegrityError) null value in column "name" violates not-null constraint
DETAIL:  Failing row contains (392, null, null, null, null, null, 176).
CONTEXT:  SQL statement "update microlocations set name = NULL where name = '';update microlocations set room = NULL where room = '';"
PL/pgSQL function replace_in_table(text,text,text,boolean) line 23 at EXECUTE
 [SQL: "SELECT replace_in_table('microlocations', '''''', 'NULL', true)"]
(25 additional frame(s) were not displayed)
...
  File "sqlalchemy/engine/base.py", line 1189, in _execute_context
    context)
  File "sqlalchemy/engine/base.py", line 1402, in _handle_dbapi_exception
    exc_info
  File "sqlalchemy/util/compat.py", line 203, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "sqlalchemy/engine/base.py", line 1182, in _execute_context
    context)
  File "sqlalchemy/engine/default.py", line 470, in do_execute
    cursor.execute(statement, parameters)

IntegrityError: (psycopg2.IntegrityError) null value in column "name" violates not-null constraint
DETAIL:  Failing row contains (392, null, null, null, null, null, 176).
CONTEXT:  SQL statement "update microlocations set name = NULL where name = '';update microlocations set room = NULL where room = '';"
PL/pgSQL function replace_in_table(text,text,text,boolean) line 23 at EXECUTE
 [SQL: "SELECT replace_in_table('microlocations', '''''', 'NULL', true)"]
```

> This error occurred when running the migrations against a clone of the production database

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `migrations/versions/1b9c8698c632_.py`
Content:
```
1 """empty message
2 
3 Revision ID: 1b9c8698c632
4 Revises: af9215895b80
5 Create Date: 2017-06-15 22:39:27.240374
6 
7 """
8 
9 # revision identifiers, used by Alembic.
10 revision = '1b9c8698c632'
11 down_revision = 'af9215895b80'
12 
13 from alembic import op
14 import sqlalchemy as sa
15 import sqlalchemy_utils
16 
17 
18 class ReplaceableObject(object):
19     def __init__(self, name, sqltext):
20         self.name = name
21         self.sqltext = sqltext
22 
23 # function to find a and replace a string(the whole string should match, not substring)
24 # across all the columns of a table.
25 # If run is true then the function executes the query.
26 replace_in_table = ReplaceableObject(
27     "replace_in_table(table_name text, original text, replacement text, run boolean)",
28     """
29     returns text language plpgsql
30     as $$
31     declare
32         r record;
33         q text;
34     begin
35         q = '';
36         for r in
37             select attname
38             from pg_attribute
39             where attrelid = table_name::regclass
40                 and attnum > 0
41                 and not attisdropped
42                 and (atttypid = 25
43                 or atttypid = 1042
44                 or atttypid = 1043)
45             order by attnum
46         loop
47             q = format($fmt$%supdate %s set %s = %s where %s = %s;$fmt$,
48                 q, table_name, r.attname, replacement, r.attname, original);
49         end loop;
50         q = format('%s;', rtrim(q, ';'));
51         if run then
52             execute q;
53         end if;
54         return q;
55     end $$;
56     """
57 )
58 
59 
60 def upgrade():
61     # ### commands auto generated by Alembic - please adjust! ###
62     op.create_or_replace_sp(replace_in_table)
63     op.alter_column('social_links', 'link',
64                     existing_type=sa.VARCHAR(),
65                     nullable=True)
66     op.alter_column('sessions', 'title',
67                     existing_type=sa.VARCHAR(),
68                     nullable=True)
69     op.alter_column('sessions_version', 'title',
70                     existing_type=sa.VARCHAR(),
71                     nullable=True)
72     op.alter_column('call_for_papers', 'announcement',
73                     existing_type=sa.VARCHAR(),
74                     nullable=True)
75 
76     # to create these statements automatically, please print them like
77     # print("""op.execute("SELECT replace_in_table('""" + table[0] + """', '''''', 'NULL', true)",
78     #           execution_options=None)""")
79     # inside the function to fetch all tables and models in the views directory
80     # TRY AS HARD AS YOU CAN TO NOT BRING THE APP LOGIC IN MIGRATIONS
81     op.execute("SELECT replace_in_table('event_copyrights', '''''', 'NULL', true)",
82                execution_options=None)
83     op.execute("SELECT replace_in_table('mails', '''''', 'NULL', true)",
84                execution_options=None)
85     op.execute("SELECT replace_in_table('social_links', '''''', 'NULL', true)",
86                execution_options=None)
87     op.execute("SELECT replace_in_table('booked_ticket', '''''', 'NULL', true)",
88                execution_options=None)
89     op.execute("SELECT replace_in_table('tax', '''''', 'NULL', true)",
90                execution_options=None)
91     op.execute("SELECT replace_in_table('custom_sys_roles', '''''', 'NULL', true)",
92                execution_options=None)
93     op.execute("SELECT replace_in_table('custom_forms', '''''', 'NULL', true)",
94                execution_options=None)
95     op.execute("SELECT replace_in_table('microlocations', '''''', 'NULL', true)",
96                execution_options=None)
97     op.execute("SELECT replace_in_table('user_permissions', '''''', 'NULL', true)",
98                execution_options=None)
99     op.execute("SELECT replace_in_table('event_user', '''''', 'NULL', true)",
100                execution_options=None)
101     op.execute("SELECT replace_in_table('orders', '''''', 'NULL', true)",
102                execution_options=None)
103     op.execute("SELECT replace_in_table('orders_tickets', '''''', 'NULL', true)",
104                execution_options=None)
105     op.execute("SELECT replace_in_table('discount_codes', '''''', 'NULL', true)",
106                execution_options=None)
107     op.execute("SELECT replace_in_table('ticket_fees', '''''', 'NULL', true)",
108                execution_options=None)
109     op.execute("SELECT replace_in_table('access_codes', '''''', 'NULL', true)",
110                execution_options=None)
111     op.execute("SELECT replace_in_table('user_system_role', '''''', 'NULL', true)",
112                execution_options=None)
113     op.execute("SELECT replace_in_table('message_settings', '''''', 'NULL', true)",
114                execution_options=None)
115     op.execute("SELECT replace_in_table('image_sizes', '''''', 'NULL', true)",
116                execution_options=None)
117     op.execute("SELECT replace_in_table('speaker', '''''', 'NULL', true)",
118                execution_options=None)
119     op.execute("SELECT replace_in_table('stripe_authorizations', '''''', 'NULL', true)",
120                execution_options=None)
121     op.execute("SELECT replace_in_table('role_invites', '''''', 'NULL', true)",
122                execution_options=None)
123     op.execute("SELECT replace_in_table('custom_placeholders', '''''', 'NULL', true)",
124                execution_options=None)
125     op.execute("SELECT replace_in_table('session_types', '''''', 'NULL', true)",
126                execution_options=None)
127     op.execute("SELECT replace_in_table('events', '''''', 'NULL', true)",
128                execution_options=None)
129     op.execute("SELECT replace_in_table('activities', '''''', 'NULL', true)",
130                execution_options=None)
131     op.execute("SELECT replace_in_table('users', '''''', 'NULL', true)",
132                execution_options=None)
133     op.execute("SELECT replace_in_table('sessions', '''''', 'NULL', true)",
134                execution_options=None)
135     op.execute("SELECT replace_in_table('sponsors', '''''', 'NULL', true)",
136                execution_options=None)
137     op.execute("SELECT replace_in_table('ticket_holders', '''''', 'NULL', true)",
138                execution_options=None)
139     op.execute("SELECT replace_in_table('notifications', '''''', 'NULL', true)",
140                execution_options=None)
141     op.execute("SELECT replace_in_table('tracks', '''''', 'NULL', true)",
142                execution_options=None)
143     op.execute("SELECT replace_in_table('users_events_roles', '''''', 'NULL', true)",
144                execution_options=None)
145     op.execute("SELECT replace_in_table('email_notifications', '''''', 'NULL', true)",
146                execution_options=None)
147     op.execute("SELECT replace_in_table('services', '''''', 'NULL', true)",
148                execution_options=None)
149     op.execute("SELECT replace_in_table('export_jobs', '''''', 'NULL', true)",
150                execution_options=None)
151     op.execute("SELECT replace_in_table('image_config', '''''', 'NULL', true)",
152                execution_options=None)
153     op.execute("SELECT replace_in_table('pages', '''''', 'NULL', true)",
154                execution_options=None)
155     op.execute("SELECT replace_in_table('permissions', '''''', 'NULL', true)",
156                execution_options=None)
157     op.execute("SELECT replace_in_table('tickets', '''''', 'NULL', true)",
158                execution_options=None)
159     op.execute("SELECT replace_in_table('roles', '''''', 'NULL', true)",
160                execution_options=None)
161     op.execute("SELECT replace_in_table('settings', '''''', 'NULL', true)",
162                execution_options=None)
163     op.execute("SELECT replace_in_table('versions', '''''', 'NULL', true)",
164                execution_options=None)
165     op.execute("SELECT replace_in_table('modules', '''''', 'NULL', true)",
166                execution_options=None)
167     op.execute("SELECT replace_in_table('event_invoices', '''''', 'NULL', true)",
168                execution_options=None)
169     op.execute("SELECT replace_in_table('import_jobs', '''''', 'NULL', true)",
170                execution_options=None)
171     op.execute("SELECT replace_in_table('call_for_papers', '''''', 'NULL', true)",
172                execution_options=None)
173     op.execute("SELECT replace_in_table('panel_permissions', '''''', 'NULL', true)",
174                execution_options=None)
175     op.execute("SELECT replace_in_table('ticket_tag', '''''', 'NULL', true)",
176                execution_options=None)
177     op.execute("SELECT replace_in_table('invites', '''''', 'NULL', true)",
178                execution_options=None)
179 
180     op.execute("SELECT replace_in_table('sessions_version', '''''', 'NULL', true)",
181                execution_options=None)
182     op.execute("SELECT replace_in_table('events_version', '''''', 'NULL', true)",
183                execution_options=None)
184     # ### end Alembic commands ###
185 
186 
187 def downgrade():
188     # ### commands auto generated by Alembic - please adjust! ###
189     op.drop_sp(replace_in_table)
190     op.alter_column('social_links', 'link',
191                     existing_type=sa.VARCHAR(),
192                     nullable=False)
193     op.alter_column('sessions', 'title',
194                     existing_type=sa.VARCHAR(),
195                     nullable=False)
196     op.alter_column('sessions_version', 'title',
197                     existing_type=sa.VARCHAR(),
198                     nullable=False)
199     op.alter_column('call_for_papers', 'announcement',
200                     existing_type=sa.VARCHAR(),
201                     nullable=False)
202     # ### end Alembic commands ###
203
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/migrations/versions/1b9c8698c632_.py b/migrations/versions/1b9c8698c632_.py
--- a/migrations/versions/1b9c8698c632_.py
+++ b/migrations/versions/1b9c8698c632_.py
@@ -23,6 +23,7 @@
 # function to find a and replace a string(the whole string should match, not substring)
 # across all the columns of a table.
 # If run is true then the function executes the query.
+# This will work only for nullable columns
 replace_in_table = ReplaceableObject(
     "replace_in_table(table_name text, original text, replacement text, run boolean)",
     """
@@ -42,6 +43,7 @@
                 and (atttypid = 25
                 or atttypid = 1042
                 or atttypid = 1043)
+                and not attnotnull
             order by attnum
         loop
             q = format($fmt$%supdate %s set %s = %s where %s = %s;$fmt$,

{"golden_diff": "diff --git a/migrations/versions/1b9c8698c632_.py b/migrations/versions/1b9c8698c632_.py\n--- a/migrations/versions/1b9c8698c632_.py\n+++ b/migrations/versions/1b9c8698c632_.py\n@@ -23,6 +23,7 @@\n # function to find a and replace a string(the whole string should match, not substring)\n # across all the columns of a table.\n # If run is true then the function executes the query.\n+# This will work only for nullable columns\n replace_in_table = ReplaceableObject(\n     \"replace_in_table(table_name text, original text, replacement text, run boolean)\",\n     \"\"\"\n@@ -42,6 +43,7 @@\n                 and (atttypid = 25\n                 or atttypid = 1042\n                 or atttypid = 1043)\n+                and not attnotnull\n             order by attnum\n         loop\n             q = format($fmt$%supdate %s set %s = %s where %s = %s;$fmt$,\n", "issue": "IntegrityError: (psycopg2.IntegrityError) null value in column \"name\" violates not-null constraint\nhttps://sentry.eventyay.com/eventyay/api/issues/14/\r\n\r\n```\r\nIntegrityError: (psycopg2.IntegrityError) null value in column \"name\" violates not-null constraint\r\nDETAIL:  Failing row contains (392, null, null, null, null, null, 176).\r\nCONTEXT:  SQL statement \"update microlocations set name = NULL where name = '';update microlocations set room = NULL where room = '';\"\r\nPL/pgSQL function replace_in_table(text,text,text,boolean) line 23 at EXECUTE\r\n [SQL: \"SELECT replace_in_table('microlocations', '''''', 'NULL', true)\"]\r\n(25 additional frame(s) were not displayed)\r\n...\r\n  File \"sqlalchemy/engine/base.py\", line 1189, in _execute_context\r\n    context)\r\n  File \"sqlalchemy/engine/base.py\", line 1402, in _handle_dbapi_exception\r\n    exc_info\r\n  File \"sqlalchemy/util/compat.py\", line 203, in raise_from_cause\r\n    reraise(type(exception), exception, tb=exc_tb, cause=cause)\r\n  File \"sqlalchemy/engine/base.py\", line 1182, in _execute_context\r\n    context)\r\n  File \"sqlalchemy/engine/default.py\", line 470, in do_execute\r\n    cursor.execute(statement, parameters)\r\n\r\nIntegrityError: (psycopg2.IntegrityError) null value in column \"name\" violates not-null constraint\r\nDETAIL:  Failing row contains (392, null, null, null, null, null, 176).\r\nCONTEXT:  SQL statement \"update microlocations set name = NULL where name = '';update microlocations set room = NULL where room = '';\"\r\nPL/pgSQL function replace_in_table(text,text,text,boolean) line 23 at EXECUTE\r\n [SQL: \"SELECT replace_in_table('microlocations', '''''', 'NULL', true)\"]\r\n```\r\n\r\n> This error occurred when running the migrations against a clone of the production database\n", "before_files": [{"content": "\"\"\"empty message\n\nRevision ID: 1b9c8698c632\nRevises: af9215895b80\nCreate Date: 2017-06-15 22:39:27.240374\n\n\"\"\"\n\n# revision identifiers, used by Alembic.\nrevision = '1b9c8698c632'\ndown_revision = 'af9215895b80'\n\nfrom alembic import op\nimport sqlalchemy as sa\nimport sqlalchemy_utils\n\n\nclass ReplaceableObject(object):\n    def __init__(self, name, sqltext):\n        self.name = name\n        self.sqltext = sqltext\n\n# function to find a and replace a string(the whole string should match, not substring)\n# across all the columns of a table.\n# If run is true then the function executes the query.\nreplace_in_table = ReplaceableObject(\n    \"replace_in_table(table_name text, original text, replacement text, run boolean)\",\n    \"\"\"\n    returns text language plpgsql\n    as $$\n    declare\n        r record;\n        q text;\n    begin\n        q = '';\n        for r in\n            select attname\n            from pg_attribute\n            where attrelid = table_name::regclass\n                and attnum > 0\n                and not attisdropped\n                and (atttypid = 25\n                or atttypid = 1042\n                or atttypid = 1043)\n            order by attnum\n        loop\n            q = format($fmt$%supdate %s set %s = %s where %s = %s;$fmt$,\n                q, table_name, r.attname, replacement, r.attname, original);\n        end loop;\n        q = format('%s;', rtrim(q, ';'));\n        if run then\n            execute q;\n        end if;\n        return q;\n    end $$;\n    \"\"\"\n)\n\n\ndef upgrade():\n    # ### commands auto generated by Alembic - please adjust! ###\n    op.create_or_replace_sp(replace_in_table)\n    op.alter_column('social_links', 'link',\n                    existing_type=sa.VARCHAR(),\n                    nullable=True)\n    op.alter_column('sessions', 'title',\n                    existing_type=sa.VARCHAR(),\n                    nullable=True)\n    op.alter_column('sessions_version', 'title',\n                    existing_type=sa.VARCHAR(),\n                    nullable=True)\n    op.alter_column('call_for_papers', 'announcement',\n                    existing_type=sa.VARCHAR(),\n                    nullable=True)\n\n    # to create these statements automatically, please print them like\n    # print(\"\"\"op.execute(\"SELECT replace_in_table('\"\"\" + table[0] + \"\"\"', '''''', 'NULL', true)\",\n    #           execution_options=None)\"\"\")\n    # inside the function to fetch all tables and models in the views directory\n    # TRY AS HARD AS YOU CAN TO NOT BRING THE APP LOGIC IN MIGRATIONS\n    op.execute(\"SELECT replace_in_table('event_copyrights', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('mails', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('social_links', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('booked_ticket', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('tax', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('custom_sys_roles', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('custom_forms', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('microlocations', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('user_permissions', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('event_user', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('orders', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('orders_tickets', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('discount_codes', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('ticket_fees', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('access_codes', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('user_system_role', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('message_settings', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('image_sizes', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('speaker', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('stripe_authorizations', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('role_invites', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('custom_placeholders', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('session_types', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('events', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('activities', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('users', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('sessions', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('sponsors', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('ticket_holders', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('notifications', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('tracks', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('users_events_roles', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('email_notifications', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('services', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('export_jobs', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('image_config', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('pages', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('permissions', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('tickets', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('roles', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('settings', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('versions', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('modules', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('event_invoices', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('import_jobs', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('call_for_papers', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('panel_permissions', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('ticket_tag', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('invites', '''''', 'NULL', true)\",\n               execution_options=None)\n\n    op.execute(\"SELECT replace_in_table('sessions_version', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('events_version', '''''', 'NULL', true)\",\n               execution_options=None)\n    # ### end Alembic commands ###\n\n\ndef downgrade():\n    # ### commands auto generated by Alembic - please adjust! ###\n    op.drop_sp(replace_in_table)\n    op.alter_column('social_links', 'link',\n                    existing_type=sa.VARCHAR(),\n                    nullable=False)\n    op.alter_column('sessions', 'title',\n                    existing_type=sa.VARCHAR(),\n                    nullable=False)\n    op.alter_column('sessions_version', 'title',\n                    existing_type=sa.VARCHAR(),\n                    nullable=False)\n    op.alter_column('call_for_papers', 'announcement',\n                    existing_type=sa.VARCHAR(),\n                    nullable=False)\n    # ### end Alembic commands ###\n", "path": "migrations/versions/1b9c8698c632_.py"}], "after_files": [{"content": "\"\"\"empty message\n\nRevision ID: 1b9c8698c632\nRevises: af9215895b80\nCreate Date: 2017-06-15 22:39:27.240374\n\n\"\"\"\n\n# revision identifiers, used by Alembic.\nrevision = '1b9c8698c632'\ndown_revision = 'af9215895b80'\n\nfrom alembic import op\nimport sqlalchemy as sa\nimport sqlalchemy_utils\n\n\nclass ReplaceableObject(object):\n    def __init__(self, name, sqltext):\n        self.name = name\n        self.sqltext = sqltext\n\n# function to find a and replace a string(the whole string should match, not substring)\n# across all the columns of a table.\n# If run is true then the function executes the query.\n# This will work only for nullable columns\nreplace_in_table = ReplaceableObject(\n    \"replace_in_table(table_name text, original text, replacement text, run boolean)\",\n    \"\"\"\n    returns text language plpgsql\n    as $$\n    declare\n        r record;\n        q text;\n    begin\n        q = '';\n        for r in\n            select attname\n            from pg_attribute\n            where attrelid = table_name::regclass\n                and attnum > 0\n                and not attisdropped\n                and (atttypid = 25\n                or atttypid = 1042\n                or atttypid = 1043)\n                and not attnotnull\n            order by attnum\n        loop\n            q = format($fmt$%supdate %s set %s = %s where %s = %s;$fmt$,\n                q, table_name, r.attname, replacement, r.attname, original);\n        end loop;\n        q = format('%s;', rtrim(q, ';'));\n        if run then\n            execute q;\n        end if;\n        return q;\n    end $$;\n    \"\"\"\n)\n\n\ndef upgrade():\n    # ### commands auto generated by Alembic - please adjust! ###\n    op.create_or_replace_sp(replace_in_table)\n    op.alter_column('social_links', 'link',\n                    existing_type=sa.VARCHAR(),\n                    nullable=True)\n    op.alter_column('sessions', 'title',\n                    existing_type=sa.VARCHAR(),\n                    nullable=True)\n    op.alter_column('sessions_version', 'title',\n                    existing_type=sa.VARCHAR(),\n                    nullable=True)\n    op.alter_column('call_for_papers', 'announcement',\n                    existing_type=sa.VARCHAR(),\n                    nullable=True)\n\n    # to create these statements automatically, please print them like\n    # print(\"\"\"op.execute(\"SELECT replace_in_table('\"\"\" + table[0] + \"\"\"', '''''', 'NULL', true)\",\n    #           execution_options=None)\"\"\")\n    # inside the function to fetch all tables and models in the views directory\n    # TRY AS HARD AS YOU CAN TO NOT BRING THE APP LOGIC IN MIGRATIONS\n    op.execute(\"SELECT replace_in_table('event_copyrights', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('mails', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('social_links', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('booked_ticket', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('tax', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('custom_sys_roles', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('custom_forms', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('microlocations', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('user_permissions', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('event_user', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('orders', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('orders_tickets', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('discount_codes', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('ticket_fees', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('access_codes', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('user_system_role', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('message_settings', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('image_sizes', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('speaker', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('stripe_authorizations', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('role_invites', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('custom_placeholders', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('session_types', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('events', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('activities', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('users', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('sessions', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('sponsors', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('ticket_holders', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('notifications', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('tracks', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('users_events_roles', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('email_notifications', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('services', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('export_jobs', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('image_config', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('pages', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('permissions', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('tickets', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('roles', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('settings', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('versions', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('modules', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('event_invoices', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('import_jobs', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('call_for_papers', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('panel_permissions', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('ticket_tag', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('invites', '''''', 'NULL', true)\",\n               execution_options=None)\n\n    op.execute(\"SELECT replace_in_table('sessions_version', '''''', 'NULL', true)\",\n               execution_options=None)\n    op.execute(\"SELECT replace_in_table('events_version', '''''', 'NULL', true)\",\n               execution_options=None)\n    # ### end Alembic commands ###\n\n\ndef downgrade():\n    # ### commands auto generated by Alembic - please adjust! ###\n    op.drop_sp(replace_in_table)\n    op.alter_column('social_links', 'link',\n                    existing_type=sa.VARCHAR(),\n                    nullable=False)\n    op.alter_column('sessions', 'title',\n                    existing_type=sa.VARCHAR(),\n                    nullable=False)\n    op.alter_column('sessions_version', 'title',\n                    existing_type=sa.VARCHAR(),\n                    nullable=False)\n    op.alter_column('call_for_papers', 'announcement',\n                    existing_type=sa.VARCHAR(),\n                    nullable=False)\n    # ### end Alembic commands ###\n", "path": "migrations/versions/1b9c8698c632_.py"}]}