Skip to content

Export SQL for a migration #7

Open

Description

@olirice

Vecs does not currently interop well with migrations.

Provide a function that exports a SQL snippet that can be used to setup a migration

Example

docs = vx.create_collection(...)

docs.export_migration()
# Returns: "create table vecs.docs ......"

Activity

  1. TemaDeveloper commented on Apr 20, 2026

    @TemaDeveloper

    Hi @olirice — happy to take this. Proposed API per the issue body:

    def export_migration(
        self,
        *,
        include_extension: bool = True,
        include_schema: bool = True,
        if_not_exists: bool = True,
    ) -> str:

    Returns the DDL needed to recreate the collection's table and metadata index, suitable for pasting into Alembic / sqitch / raw migration files. Sample output for create_collection(name="docs", dimension=3):

    create extension if not exists vector;
    create schema if not exists vecs;
    CREATE TABLE IF NOT EXISTS vecs.docs (
        id VARCHAR NOT NULL,
        vec VECTOR(3) NOT NULL,
        metadata JSONB DEFAULT '{}'::jsonb NOT NULL,
        PRIMARY KEY (id)
    );
    create index if not exists ix_meta_docs
      on vecs."docs" using gin (metadata jsonb_path_ops);

    Two design choices I'd like to confirm before I open a PR:

    1. Index naming. _create currently uses ix_meta_<uuid> for the metadata GIN index to avoid collisions. For a migration this needs to be deterministic, so I'd switch to ix_meta_<collection_name>. Sound right, or would you prefer the caller pass an explicit name?
    2. Vector indexes excluded. create_index picks n_lists from the current row count and chooses HNSW vs IVFFlat from the live pgvector version, so I'd leave it out of export_migration. Users would still call collection.create_index() after data is loaded. Agree, or do you want a separate export_index_migration(method=..., n_lists=...)?

    I have an implementation + tests ready locally; happy to push as soon as you ack the approach. PR will follow the Conventional Commits format (feat(collection): add export_migration for SQL DDL export) and link back to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions