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.2a0.tar.gz (28.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.2a0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pelican_migration-0.1.2a0.tar.gz
  • Upload date:
  • Size: 28.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.2a0.tar.gz
Algorithm Hash digest
SHA256 ba102de065795765519b74f734a2f4738b366933bcfb30064d367e8c04a92ae6
MD5 2cc96811231fd1b0bc088882108c7444
BLAKE2b-256 276e4f5823e8c44b786e1954a8ed8b0411182692204c7fb470132f736bfef127

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pelican_migration-0.1.2a0-py3-none-any.whl
Algorithm Hash digest
SHA256 f636974906070ec7c1bc5fc7d070d01866c638447ac515c5223630639ff2ac83
MD5 c8021f51d468fd8da37057cdd9a00d59
BLAKE2b-256 b38dbde801987f3c806ce33727ed5cd035b27c252ddc43d44a45eb4a778db5d7

See more details on using hashes here.

Provenance

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