From c78d9a5c7f518cf680319a28cdb793ca2a570a8b Mon Sep 17 00:00:00 2001 From: Agent Zero Date: Thu, 6 Aug 2026 23:14:29 +0200 Subject: [PATCH] fix(migrations): make 0110 safe for fresh installs mail_accounts is a plugin table created after core migrations. Wrap ALTER TABLE in DO $$ IF EXISTS block. --- ...0110_add_password_salt_to_mail_accounts.py | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/alembic/versions/0110_add_password_salt_to_mail_accounts.py b/alembic/versions/0110_add_password_salt_to_mail_accounts.py index b0ec270..f1ec576 100644 --- a/alembic/versions/0110_add_password_salt_to_mail_accounts.py +++ b/alembic/versions/0110_add_password_salt_to_mail_accounts.py @@ -26,14 +26,27 @@ depends_on = None def upgrade() -> None: + # Only add the column if the mail_accounts table exists. + # On fresh installs, mail_accounts is created by the mail plugin's own + # migration (0001_initial.sql) which runs AFTER core alembic migrations. op.execute( - "ALTER TABLE mail_accounts " - "ADD COLUMN IF NOT EXISTS password_salt VARCHAR(64) NOT NULL DEFAULT ''" + "DO $$ " + "BEGIN " + " IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'mail_accounts') THEN " + " ALTER TABLE mail_accounts " + " ADD COLUMN IF NOT EXISTS password_salt VARCHAR(64) NOT NULL DEFAULT ''; " + " END IF; " + "END $$" ) def downgrade() -> None: op.execute( - "ALTER TABLE mail_accounts " - "DROP COLUMN IF EXISTS password_salt" + "DO $$ " + "BEGIN " + " IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'mail_accounts') THEN " + " ALTER TABLE mail_accounts " + " DROP COLUMN IF EXISTS password_salt; " + " END IF; " + "END $$" )