https://github.com/alex-oleshkevich/headlight
A database migration toolkit for Python.
https://github.com/alex-oleshkevich/headlight
Last synced: about 2 months ago
JSON representation
A database migration toolkit for Python.
- Host: GitHub
- URL: https://github.com/alex-oleshkevich/headlight
- Owner: alex-oleshkevich
- License: mit
- Created: 2022-07-25T18:22:36.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-03-20T16:34:22.000Z (about 1 year ago)
- Last Synced: 2025-02-24T18:08:16.975Z (2 months ago)
- Language: Python
- Size: 267 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.rst
- License: LICENSE
Awesome Lists containing this project
README
# headlight
A database migration toolkit.





## Installation
Install `headlight` using PIP or poetry:
```bash
pip install headlight
# or
poetry add headlight
```## Features
- fluent migration builders
- PostreSQL support (only)
- rollback migrations
- powerful CLI
- command line utilities are embeddable into your Click application## Usage
### Create migration file
```bash
# create migration with
headlight new --name initial
```It will create a new python file in `migrations` directory
### Define schema
```python
# migrations/0000_initial.pyfrom headlight import Blueprint, types
date = "2022-08-21T16:19:13.465195"
author = "alex"
transactional = Truedef migrate(schema: Blueprint) -> None:
with schema.create_table('users') as table:
table.autoincrements()
table.add_column('first_name', types.VarCharType(256))
table.add_column('last_name', types.VarCharType(256))
table.add_column('email', types.VarCharType(256))
table.add_column('password', types.VarCharType(512))
table.add_column('active', types.BooleanType(), default=True)
table.add_column('photo', types.VarCharType(512), null=True)
table.add_column('deleted_at', types.DateTimeType(True), null=True)
table.add_created_timestamp('joined_at')
table.add_index(['(lower(email))'], unique=True)
```### Execute migration
```bash
headlight upgrade
```All migrations will be applied to the database
### Rollback migration
```bash
headlight downgrade
```The last migration will be rolled back,