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.0a0.tar.gz (22.8 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.0a0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pelican_migration-0.1.0a0.tar.gz
  • Upload date:
  • Size: 22.8 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.0a0.tar.gz
Algorithm Hash digest
SHA256 0f76b0d15c1daf966989471704edff1b6cba1921243cf85950d80f7b72ba9cf3
MD5 7508931e134aa3854dc4a6b89a8250f3
BLAKE2b-256 8d26ec4a5c345d7ce2b4124f85a777b8c7ae2c06193ae23cbe3b566388158443

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pelican_migration-0.1.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 9dec7aeef7743a8405d2632b4a51b565f7082afa2842107281ff863677061881
MD5 98e96c4d7f500cfe3cde937e55bf85cc
BLAKE2b-256 1a4aaa3b1210c50eb611e112da5f8c64749e4ebadd3a599f2799d030675044ad

See more details on using hashes here.

Provenance

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