new file: authentication/.env
new file: authentication/Dockerfile new file: authentication/Makefile new file: authentication/__pycache__/main.cpython-313.pyc new file: authentication/database-migration/Dockerfile new file: authentication/database-migration/data.db new file: authentication/database-migration/db_migration.py new file: authentication/database-migration/migration.py new file: authentication/database-migration/requirements.txt new file: authentication/docker-compose.migration.yml new file: authentication/docker-compose.yml new file: authentication/main.py new file: authentication/requirements.txt
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
print('RUNNING!')
|
||||
|
||||
import sqlite3
|
||||
import os
|
||||
import psycopg
|
||||
|
||||
print(os.getcwd())
|
||||
print(os.listdir())
|
||||
|
||||
with open('data.db', 'rb') as f:
|
||||
data = f.read()
|
||||
print(f'[DEBUG] Begin SQLite database')
|
||||
print(data)
|
||||
print(f'[DEBUG] End SQLite database')
|
||||
|
||||
|
||||
conn = psycopg.connect(
|
||||
host = 'db',
|
||||
port = 5432,
|
||||
dbname = os.getenv('POSTGRES_DB'),
|
||||
user = os.getenv('POSTGRES_USER'),
|
||||
password = os.getenv('POSTGRES_PASSWORD')
|
||||
)
|
||||
|
||||
cursor = conn.cursor()
|
||||
|
||||
with sqlite3.connect('data.db') as sqlite3_conn:
|
||||
sqlite_cursor = sqlite3_conn.cursor()
|
||||
sqlite_cursor.execute('SELECT COUNT(*) FROM data')
|
||||
number_of_users = sqlite_cursor.fetchone()[0]
|
||||
for user in range(1, number_of_users + 1):
|
||||
print(f'Migrating user {user} ...')
|
||||
sqlite_cursor.execute('SELECT (id, email, remail, phone, password) FROM data WHERE id = ?', (user,))
|
||||
cursor.execute('INSERT INTO users (id, email, remail, phone, password) VALUES (%s, %s, %s, %s, %s)', tuple(sqlite_cursor.fetchone()))
|
||||
cursor.execute('SELECT setval(pg_get_serial_sequence(\'users\', \'id\'), (SELECT MAX(id) FROM users), true)')
|
||||
sqlite_cursor.close()
|
||||
|
||||
print('[INFO] Migration completed')
|
||||
Reference in New Issue
Block a user