Skip to main content

A modern migration tool for SQLAlchemy.

Project description

Pelican

A modern, minimal migration framework for SQLAlchemy

Tests CodeQL Advanced PyPI - Version OpenSSF Scorecard

DocumentationSource Code

Pelican is a lightweight tool for managing database schema changes. It focuses on readability, simplicity and clean developer experience.

"""20251002014707 - Create spaceships"""
from pelican import migration, create_table, drop_table


@migration.up
def upgrade():
    with create_table('spaceships') as t:
        t.string('name', nullable=False)
        t.integer('crew_capacity', default=1)
        t.timestamps()


@migration.down
def downgrade():
    drop_table('spaceships')

Installation

Create and activate a virtual environment and install Pelican:

pip install pelican-migration

Configuration

Pelican reads the database URL from a DATABASE_URL environment variable or a .env file in your project root:

DATABASE_URL=postgresql://user:password@localhost/mydb

Supported databases: SQLite, PostgreSQL.

Usage

Generate a migration

pelican generate create_spaceships

Creates db/migrations/<timestamp>_create_spaceships.py from the default template.

Apply migrations

pelican up          # apply all pending migrations
pelican up 123      # apply a specific revision

Roll back

pelican down        # roll back the latest applied migration
pelican down 123    # roll back a specific revision

Check status

pelican status
Migration Status
------------------------------
✓ 20251001120000 Create users
✓ 20251002014707 Create spaceships
○ 20251003090000 Add crew manifest

Schema DSL

create_table

from pelican import create_table

with create_table('spaceships') as t:
    t.string('name', nullable=False)
    t.integer('crew_capacity', default=1)
    t.boolean('active', default=True)
    t.text('description')
    t.references('user')        # adds user_id FK → users.id
    t.timestamps()              # adds created_at and updated_at
    t.index(['name'], unique=True)

change_table

from pelican import change_table

with change_table('spaceships') as t:
    t.string('designation')         # add column
    t.rename('name', 'full_name')   # rename column
    t.drop('description')           # drop column
    t.remove_index(['full_name'])    # drop index

drop_table

from pelican import drop_table

drop_table('spaceships')

Column types

Method SQLAlchemy type
t.integer(name) Integer
t.float(name) Float
t.double(name) Double
t.boolean(name) Boolean
t.string(name, length=255) String
t.text(name) Text
t.datetime(name) DateTime
t.timestamps() created_at + updated_at
t.references(model) Integer FK to <model_plural>.id

All methods accept standard SQLAlchemy column kwargs (nullable, default, index, etc.).

Contributing

  • Fork the repository.
  • Install the development dependencies:
    pip install -e ".[dev]"
    
  • Open a PR with your improvements.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pelican_migration-0.1.3a0.tar.gz (43.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pelican_migration-0.1.3a0-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file pelican_migration-0.1.3a0.tar.gz.

File metadata

  • Download URL: pelican_migration-0.1.3a0.tar.gz
  • Upload date:
  • Size: 43.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pelican_migration-0.1.3a0.tar.gz
Algorithm Hash digest
SHA256 fde73ab84eebf4192b81b41eddda81ce881b40e143728fb227adee80a2fd69c7
MD5 be659a207e2b956c18e225706b3d9321
BLAKE2b-256 ba027f201e4317a4d22bdd9aa481e0c0863b37af9e2d141e10d9fadb6237f8f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pelican_migration-0.1.3a0.tar.gz:

Publisher: publish.yml on PenguinBoi12/pelican

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pelican_migration-0.1.3a0-py3-none-any.whl.

File metadata

File hashes

Hashes for pelican_migration-0.1.3a0-py3-none-any.whl
Algorithm Hash digest
SHA256 f20d9bfff7fdf34627c5d7355d0331d32a46020a605fb507cef01beb7adddd77
MD5 424e603f0fcc469cc4a07c827a0e6759
BLAKE2b-256 9dd0556edf87a877ad7f0dadb80c9640d51ca5841391bf317fd8c452b90084cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pelican_migration-0.1.3a0-py3-none-any.whl:

Publisher: publish.yml on PenguinBoi12/pelican

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page