mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-02 04:12:47 +02:00
Merge pull request #1069 from CREDO23/fix/zero-cache
[Fix] Make migration 109 idempotent
This commit is contained in:
commit
b1631cd6f1
1 changed files with 65 additions and 55 deletions
|
|
@ -11,6 +11,7 @@ index to correctly handle NULL parent_id at root level.
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy import inspect
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
|
||||||
|
|
@ -21,6 +22,11 @@ depends_on: str | Sequence[str] | None = None
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
|
conn = op.get_bind()
|
||||||
|
inspector = inspect(conn)
|
||||||
|
existing_tables = inspector.get_table_names()
|
||||||
|
|
||||||
|
if "folders" not in existing_tables:
|
||||||
op.create_table(
|
op.create_table(
|
||||||
"folders",
|
"folders",
|
||||||
sa.Column("id", sa.Integer(), primary_key=True, index=True),
|
sa.Column("id", sa.Integer(), primary_key=True, index=True),
|
||||||
|
|
@ -65,6 +71,8 @@ def upgrade() -> None:
|
||||||
# PostgreSQL treats NULL != NULL in regular unique constraints, so a standard
|
# PostgreSQL treats NULL != NULL in regular unique constraints, so a standard
|
||||||
# UniqueConstraint(search_space_id, parent_id, name) would allow duplicate
|
# UniqueConstraint(search_space_id, parent_id, name) would allow duplicate
|
||||||
# folder names at the root level.
|
# folder names at the root level.
|
||||||
|
existing_indexes = [idx["name"] for idx in inspector.get_indexes("folders")]
|
||||||
|
if "uq_folder_space_parent_name" not in existing_indexes:
|
||||||
op.execute(
|
op.execute(
|
||||||
"""
|
"""
|
||||||
CREATE UNIQUE INDEX uq_folder_space_parent_name
|
CREATE UNIQUE INDEX uq_folder_space_parent_name
|
||||||
|
|
@ -72,6 +80,8 @@ def upgrade() -> None:
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
existing_columns = [col["name"] for col in inspector.get_columns("documents")]
|
||||||
|
if "folder_id" not in existing_columns:
|
||||||
op.add_column(
|
op.add_column(
|
||||||
"documents",
|
"documents",
|
||||||
sa.Column(
|
sa.Column(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue