From d1eb49cb834eebf67cb1bffe2e430befb5a9348a Mon Sep 17 00:00:00 2001 From: orohi Date: Sun, 26 Jul 2026 00:21:20 +0300 Subject: [PATCH] Fix Postgres startup: add xui_email before creating its index. Co-authored-by: Cursor --- db/connection.py | 11 ++++------- db/schema.sql | 2 -- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/db/connection.py b/db/connection.py index cf1bacc..20e7752 100644 --- a/db/connection.py +++ b/db/connection.py @@ -77,13 +77,10 @@ def init_schema(): stmt = '\n'.join(lines).strip() if stmt: cur.execute(stmt) - conn.commit() - # Soft migrations for existing databases - with pool.connection() as conn: - with conn.cursor() as cur: - cur.execute( - "ALTER TABLE users ADD COLUMN IF NOT EXISTS xui_email TEXT" - ) + + # Soft migrations: CREATE TABLE IF NOT EXISTS does not add new columns + # to existing tables, so alter after base schema is applied. + cur.execute("ALTER TABLE users ADD COLUMN IF NOT EXISTS xui_email TEXT") cur.execute( "CREATE INDEX IF NOT EXISTS idx_users_xui_email ON users(xui_email)" ) diff --git a/db/schema.sql b/db/schema.sql index 2cdacfe..853a582 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -35,8 +35,6 @@ CREATE TABLE IF NOT EXISTS users ( share_password_hash TEXT ); -CREATE INDEX IF NOT EXISTS idx_users_xui_email ON users(xui_email); - CREATE TABLE IF NOT EXISTS user_connections ( id UUID PRIMARY KEY, user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,