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.1a0.tar.gz (26.4 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.1a0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pelican_migration-0.1.1a0.tar.gz
  • Upload date:
  • Size: 26.4 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.1a0.tar.gz
Algorithm Hash digest
SHA256 0db95c35fb0cfea468857c8a5fa9c0d18d767f289563e11072527d6c043bfad8
MD5 3108887f355c02709d071c94130214e7
BLAKE2b-256 7af2accb6a60ecbbcd58d0c4a05a8706f4071c5e21dc64aeb9fe7d2956bf18e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pelican_migration-0.1.1a0.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.1a0-py3-none-any.whl.

File metadata

File hashes

Hashes for pelican_migration-0.1.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 315358376d4eafb1e0c4048c3dfd2af9d7ac139a468b11aa276b9a3554cde20b
MD5 03b437c5275da3985257cf2180cb45f1
BLAKE2b-256 0d3b2202cba1cb33ada40cf7d2c8c60d9867a27938f919002642fb52d033546f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pelican_migration-0.1.1a0-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