Metadata-Version: 2.4
Name: pelican-migration
Version: 0.1.2a0
Summary: A modern migration tool for SQLAlchemy.
Project-URL: Source, https://github.com/PenguinBoi12/pelican
Project-URL: Repository, https://github.com/PenguinBoi12/pelican.git
Project-URL: Issues, https://github.com/PenguinBoi12/pelican/issues
Author-email: Simon Roy <simon.roy1211@gmail.com>
Maintainer-email: Simon Roy <simon.roy1211@gmail.com>
License: The MIT License (MIT)
        
        Copyright (c) 2025 Simon Roy
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in
        all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
        THE SOFTWARE.
License-File: LICENSE
Keywords: alembic,cli,database,migration,orm,postgresql,schema,sqlalchemy,sqlite
Requires-Python: >=3.12
Requires-Dist: click==8.3.2
Requires-Dist: inflection==0.5.1
Requires-Dist: python-dotenv==1.2.2
Requires-Dist: sqlalchemy==2.0.49
Requires-Dist: sqlmodel==0.0.38
Provides-Extra: dev
Requires-Dist: black==26.3.1; extra == 'dev'
Requires-Dist: mypy==1.20.1; extra == 'dev'
Requires-Dist: pytest==9.0.3; extra == 'dev'
Provides-Extra: doc
Requires-Dist: mkdocs-material==9.7.6; extra == 'doc'
Requires-Dist: mkdocs==1.6.1; extra == 'doc'
Requires-Dist: mkdocstrings[python]>=1.0.4; extra == 'doc'
Description-Content-Type: text/markdown

# Pelican

> A modern, minimal migration framework for SQLAlchemy

[![Tests](https://github.com/PenguinBoi12/pelican/actions/workflows/tests.yml/badge.svg)](https://github.com/PenguinBoi12/pelican/actions/workflows/tests.yml)
[![CodeQL Advanced](https://github.com/PenguinBoi12/pelican/actions/workflows/codeql.yml/badge.svg)](https://github.com/PenguinBoi12/pelican/actions/workflows/codeql.yml)
[![PyPI - Version](https://img.shields.io/pypi/v/pelican-migration)](https://pypi.org/project/pelican-migration/)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/PenguinBoi12/pelican/badge)](https://securityscorecards.dev/viewer/?uri=github.com/PenguinBoi12/pelican)

**[Documentation](https://penguinboi12.github.io/pelican)** •
**[Source Code](https://github.com/PenguinBoi12/pelican)**

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

```python
"""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](https://docs.python.org/3/library/venv.html) and install Pelican:

```bash
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

```bash
pelican generate create_spaceships
```

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

### Apply migrations

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

### Roll back

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

### Check status

```bash
pelican status
```

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

## Schema DSL

### create_table

```python
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

```python
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

```python
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:
  ```bash
  pip install -e ".[dev]"
  ```
- Open a PR with your improvements.
