32 lines
962 B
Python
32 lines
962 B
Python
|
|
from seed_data import seed_database
|
||
|
|
from functions.database import Base, engine, get_db_connection
|
||
|
|
import time
|
||
|
|
import os
|
||
|
|
|
||
|
|
def wait_for_db():
|
||
|
|
db_path = os.path.expanduser("~/.local/share/controles/database.db")
|
||
|
|
max_attempts = 30
|
||
|
|
attempt = 0
|
||
|
|
|
||
|
|
while attempt < max_attempts:
|
||
|
|
if os.path.exists(db_path):
|
||
|
|
try:
|
||
|
|
db = get_db_connection()
|
||
|
|
db.execute("SELECT 1")
|
||
|
|
return True
|
||
|
|
except:
|
||
|
|
pass
|
||
|
|
print(f"Aguardando banco de dados... tentativa {attempt + 1}/{max_attempts}")
|
||
|
|
time.sleep(1)
|
||
|
|
attempt += 1
|
||
|
|
|
||
|
|
return False
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
print("Aguardando banco de dados estar pronto...")
|
||
|
|
if wait_for_db():
|
||
|
|
print("Iniciando população do banco de dados...")
|
||
|
|
seed_database()
|
||
|
|
print("Banco de dados populado com sucesso!")
|
||
|
|
else:
|
||
|
|
print("Erro: Banco de dados não ficou pronto a tempo.")
|