diff --git a/scripts/create_light_sql.py b/scripts/create_light_sql.py
index 31c615fcf..f2ae72f85 100644
--- a/scripts/create_light_sql.py
+++ b/scripts/create_light_sql.py
@@ -9,6 +9,9 @@
r'ALTER TABLE ONLY (?P
public\.\w+)\s+ADD CONSTRAINT (?P["\w]+) FOREIGN KEY \((?P\w+)\) REFERENCES (?Ppublic\.\w+)\((?P\w+)\)(?P[^;]*);'
)
TABLE_RE = re.compile(r"CREATE TABLE (public\.\w+) ")
+SEQUENCE_RE = re.compile(
+ r"ALTER TABLE ONLY (?Ppublic\.\w+) ALTER COLUMN (?P\w+) SET DEFAULT nextval\('(?Ppublic\.\w+)'::regclass\);"
+)
SQL_TEMPLATE = """
ALTER TABLE ONLY {table}
@@ -206,8 +209,26 @@ def generate_copy_script(
outfile.write(cmd)
outfile.write("unset PGPASSWORD\n")
+ EXTRA_SQL = [
+ "UPDATE account_user SET password = ''",
+ "UPDATE public.publicbody_publicbody SET _created_by_id = NULL",
+ "UPDATE public.publicbody_publicbody SET _updated_by_id = NULL",
+ ]
+ for sql in EXTRA_SQL:
+ outfile.write(
+ f"""psql -c "{escape_quote(sql)}" {target_connection} {target_db}\n"""
+ )
+
outfile.write(f"psql {target_connection} {target_db} < constraints.sql\n")
+ matches = SEQUENCE_RE.findall(schema)
+ for match in matches:
+ table, column, sequence = match
+ sql = f"""SELECT SETVAL('{sequence}', COALESCE(MAX({column}), 1) ) FROM {table};"""
+ outfile.write(
+ f"""psql -c "{escape_quote(sql)}" {target_connection} {target_db}\n"""
+ )
+
def show_unsafe(safe_tables="safe_tables.txt", schema_file="schema.sql"):
with open(schema_file) as f: