Spaces:
Running
Running
File size: 1,058 Bytes
3cfe75a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import os
import psycopg2
from dotenv import load_dotenv
load_dotenv()
# Usar DATABASE_URL del archivo .env
DATABASE_URL = os.getenv("DATABASE_URL")
# Fallback
if not DATABASE_URL:
DATABASE_URL = "postgresql://postgres.egkydqberhebzkqtltic:Isaac%23105%2Amay%40@aws-1-us-east-1.pooler.supabase.com:6543/postgres"
def migrate():
print("Conectando a la base de datos...")
conn = psycopg2.connect(DATABASE_URL)
cur = conn.cursor()
print("Agregando columnas 'is_repertoire_only' y 'parent_lyric_id' a la tabla 'lyrics'...")
try:
cur.execute("ALTER TABLE lyrics ADD COLUMN IF NOT EXISTS is_repertoire_only BOOLEAN DEFAULT FALSE;")
cur.execute("ALTER TABLE lyrics ADD COLUMN IF NOT EXISTS parent_lyric_id INTEGER NULL REFERENCES lyrics(id) ON DELETE SET NULL;")
conn.commit()
print("Columnas agregadas exitosamente.")
except Exception as e:
print("Error al agregar columnas:", e)
conn.rollback()
cur.close()
conn.close()
if __name__ == "__main__":
migrate()
|