mirror of
https://github.com/quay/quay.git
synced 2026-01-26 06:21:37 +03:00
* Add sqlite db support on quay start up * Add batchmode to migration scripts to support sqlite db * Add sqlite db to config-tool validator + alembic migration * Fix migration script to prevent db row locking Added commit statement to ensure previous transaction is completed before the next one within the same table * Clean up unused sqlite volume * Apply black formatting to migration scripts * Address review comments * Ensure py39-unit test runs the alembic migration on Sqlite * Add static type checking for alembic config file name * alembic remove commit and invalidate during migration When disconnecting from db, alembic tries to rollback causing PendingRollbackError * Bump go version in config-tool Dockerfile * Explicitly commit transaction to prevent db table locking * Clean up + remove debug statements * Undo database secret key change * Add TEST_DATABASE_URI to py39-unit to run unit test with sqlite db * Drop index before dropping column to prevent sqlite error * Add test coverage + address last set of reviews --------- Signed-off-by: harishsurf <hgovinda@redhat.com>
21 lines
1002 B
Python
21 lines
1002 B
Python
def copy_table_contents(source_table, destination_table, conn):
|
|
if conn.engine.name == "postgresql":
|
|
conn.execute('INSERT INTO "%s" SELECT * FROM "%s"' % (destination_table, source_table))
|
|
result = list(conn.execute('Select Max(id) from "%s"' % destination_table))[0]
|
|
if result[0] is not None:
|
|
new_start_id = result[0] + 1
|
|
conn.execute(
|
|
'ALTER SEQUENCE "%s_id_seq" RESTART WITH %s' % (destination_table, new_start_id)
|
|
)
|
|
else:
|
|
conn.execute(
|
|
"INSERT INTO `%s` SELECT * FROM `%s` WHERE 1" % (destination_table, source_table)
|
|
)
|
|
if conn.engine.name != "sqlite":
|
|
result = list(conn.execute("Select Max(id) from `%s` WHERE 1" % destination_table))[0]
|
|
if result[0] is not None:
|
|
new_start_id = result[0] + 1
|
|
conn.execute(
|
|
"ALTER TABLE `%s` AUTO_INCREMENT = %s" % (destination_table, new_start_id)
|
|
)
|