mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-30 21:59:46 +02:00
feat(oauth): add checks for oauth_account table existence before migration
This commit is contained in:
parent
e5aded5a65
commit
f3a4437acd
1 changed files with 25 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ Revises: 168
|
||||||
|
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
|
||||||
revision: str = "169"
|
revision: str = "169"
|
||||||
|
|
@ -14,7 +15,28 @@ branch_labels: str | Sequence[str] | None = None
|
||||||
depends_on: str | Sequence[str] | None = None
|
depends_on: str | Sequence[str] | None = None
|
||||||
|
|
||||||
|
|
||||||
|
def _oauth_account_table_exists() -> bool:
|
||||||
|
bind = op.get_bind()
|
||||||
|
return bool(
|
||||||
|
bind.execute(
|
||||||
|
sa.text(
|
||||||
|
"""
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM information_schema.tables
|
||||||
|
WHERE table_schema = current_schema()
|
||||||
|
AND table_name = 'oauth_account'
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
).scalar()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
|
if not _oauth_account_table_exists():
|
||||||
|
return
|
||||||
|
|
||||||
op.execute(
|
op.execute(
|
||||||
"""
|
"""
|
||||||
UPDATE oauth_account AS legacy
|
UPDATE oauth_account AS legacy
|
||||||
|
|
@ -32,6 +54,9 @@ def upgrade() -> None:
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
|
if not _oauth_account_table_exists():
|
||||||
|
return
|
||||||
|
|
||||||
op.execute(
|
op.execute(
|
||||||
"""
|
"""
|
||||||
UPDATE oauth_account AS canonical
|
UPDATE oauth_account AS canonical
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue