Skip to content

Update database alembic migration recipe generation #754

Open
@slint

Description

@slint

There's a simpler and probably more correct way to generate Alembic migration compared to the existing docs from https://inveniordm.docs.cern.ch/develop/howtos/alembic/#failing-alembic-commands

The gist of it is:

# In the module you're creating the recipe
python -m venv .venv
source .venv/bin/activate

# Install the package in editable mode with all dependencies (including tests)
pip install -e .[tests,opensearch2]

# Create the alembic directory in the module
mkdir -p invenio_foobar/alembic
cd invenio_foobar/alembic

# Create the initial recipe
invenio alembic revision --path `pwd` --empty --branch invenio_foobar "Create foobar branch"

# Start a test container for the DB
eval "$(docker-services-cli up --db ${DB:-postgresql} --env)"

# Export the DB URI so that `invenio` commands are aware
export INVENIO_SQLALCHEMY_DATABASE_URI=${SQLALCHEMY_DATABASE_URI}

# Create the database
invenio db create

# Manually delete your module's tables
psql ${SQLALCHEMY_DATABASE_URI} -c "DROP TABLE foobar_table CASCADE;"

# Creat the alembic table on latest known heads
invenio alembic stamp

# Create the migration
invenio alembic revision -p "<parent recipe ID>" -d "<dependent recipe ID>" "Create base tables."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions