Added OpenAI large embedding / improve migration and upgrade handling for containers
This commit is contained in:
@@ -99,6 +99,16 @@ def run_migrations_online():
|
||||
poolclass=NullPool,
|
||||
)
|
||||
|
||||
def process_revision_directives(context, revision, directives):
|
||||
if config.cmd_opts.autogenerate:
|
||||
script = directives[0]
|
||||
if script.upgrade_ops is not None:
|
||||
# Add import for pgvector and set search path
|
||||
script.upgrade_ops.ops.insert(0, sa.schema.ExecuteSQLOp(
|
||||
"SET search_path TO CURRENT_SCHEMA(), public; IMPORT pgvector",
|
||||
execution_options=None
|
||||
))
|
||||
|
||||
with connectable.connect() as connection:
|
||||
print(tenants)
|
||||
for tenant in tenants:
|
||||
@@ -106,17 +116,18 @@ def run_migrations_online():
|
||||
# set search path on the connection, which ensures that
|
||||
# PostgreSQL will emit all CREATE / ALTER / DROP statements
|
||||
# in terms of this schema by default
|
||||
connection.execute(text(f'SET search_path TO "{tenant}"'))
|
||||
connection.execute(text(f'SET search_path TO "{tenant}", public'))
|
||||
# in SQLAlchemy v2+ the search path change needs to be committed
|
||||
connection.commit()
|
||||
|
||||
# make use of non-supported SQLAlchemy attribute to ensure
|
||||
# the dialect reflects tables in terms of the current tenant name
|
||||
connection.dialect.default_schema_name = tenant
|
||||
connection.dialect.default_schema_name = str(tenant)
|
||||
|
||||
context.configure(
|
||||
connection=connection,
|
||||
target_metadata=get_metadata(),
|
||||
process_revision_directives=process_revision_directives,
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
|
||||
Reference in New Issue
Block a user