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.
This commit is contained in:
@@ -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 $$"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user