import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
from sqlalchemy.orm.session import sessionmaker

from api.actions import update_meta_search

# revision identifiers, used by Alembic.
revision = "1a73867b1e79"
down_revision = "1c6e2fb3d3b6"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "meta_search",
        sa.Column("schema", sa.String(length=100), nullable=False),
        sa.Column("table", sa.String(length=100), nullable=False),
        sa.Column("comment", postgresql.TSVECTOR(), nullable=True),
        sa.PrimaryKeyConstraint("schema", "table"),
        schema="public",
    )
    conn = op.get_bind()
    meta = sa.MetaData(bind=conn)
    meta.reflect()

    for table in meta.tables.values():
        update_meta_search(table.name, table.schema)



def downgrade():
    op.drop_table("meta_search", schema="public")

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
from sqlalchemy.orm.session import sessionmaker

from api.actions import update_meta_search
from dataedit.views import schema_whitelist

# revision identifiers, used by Alembic.
revision = "1a73867b1e79"
down_revision = "1c6e2fb3d3b6"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "meta_search",
        sa.Column("schema", sa.String(length=100), nullable=False),
        sa.Column("table", sa.String(length=100), nullable=False),
        sa.Column("comment", postgresql.TSVECTOR(), nullable=True),
        sa.PrimaryKeyConstraint("schema", "table"),
        schema="public",
    )
    conn = op.get_bind()
    meta = sa.MetaData(bind=conn)
    meta.reflect()

    for table in meta.tables.values():
        if table.schema in schema_whitelist:
            update_meta_search(table.name, table.schema)



def downgrade():
    op.drop_table("meta_search", schema="public")

Update only tables in visible schemas
Update only tables in visible schemas

  import sqlalchemy as sa
  from alembic import op
  from sqlalchemy.dialects import postgresql
  from sqlalchemy.orm.session import sessionmaker
  
  from api.actions import update_meta_search
+ from dataedit.views import schema_whitelist
  
  # revision identifiers, used by Alembic.
  revision = "1a73867b1e79"
  down_revision = "1c6e2fb3d3b6"
  branch_labels = None
  depends_on = None
  
  
  def upgrade():
      # ### commands auto generated by Alembic - please adjust! ###
      op.create_table(
          "meta_search",
          sa.Column("schema", sa.String(length=100), nullable=False),
          sa.Column("table", sa.String(length=100), nullable=False),
          sa.Column("comment", postgresql.TSVECTOR(), nullable=True),
          sa.PrimaryKeyConstraint("schema", "table"),
          schema="public",
      )
      conn = op.get_bind()
      meta = sa.MetaData(bind=conn)
      meta.reflect()
  
      for table in meta.tables.values():
+         if table.schema in schema_whitelist:
-         update_meta_search(table.name, table.schema)
+             update_meta_search(table.name, table.schema)
  
  
  
  def downgrade():
      op.drop_table("meta_search", schema="public")
  
Update only tables in visible schemas
## Code Before:
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
from sqlalchemy.orm.session import sessionmaker

from api.actions import update_meta_search

# revision identifiers, used by Alembic.
revision = "1a73867b1e79"
down_revision = "1c6e2fb3d3b6"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "meta_search",
        sa.Column("schema", sa.String(length=100), nullable=False),
        sa.Column("table", sa.String(length=100), nullable=False),
        sa.Column("comment", postgresql.TSVECTOR(), nullable=True),
        sa.PrimaryKeyConstraint("schema", "table"),
        schema="public",
    )
    conn = op.get_bind()
    meta = sa.MetaData(bind=conn)
    meta.reflect()

    for table in meta.tables.values():
        update_meta_search(table.name, table.schema)



def downgrade():
    op.drop_table("meta_search", schema="public")

## Instruction:
Update only tables in visible schemas
## Code After:
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
from sqlalchemy.orm.session import sessionmaker

from api.actions import update_meta_search
from dataedit.views import schema_whitelist

# revision identifiers, used by Alembic.
revision = "1a73867b1e79"
down_revision = "1c6e2fb3d3b6"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "meta_search",
        sa.Column("schema", sa.String(length=100), nullable=False),
        sa.Column("table", sa.String(length=100), nullable=False),
        sa.Column("comment", postgresql.TSVECTOR(), nullable=True),
        sa.PrimaryKeyConstraint("schema", "table"),
        schema="public",
    )
    conn = op.get_bind()
    meta = sa.MetaData(bind=conn)
    meta.reflect()

    for table in meta.tables.values():
        if table.schema in schema_whitelist:
            update_meta_search(table.name, table.schema)



def downgrade():
    op.drop_table("meta_search", schema="public")
