-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
181 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# simple-migrations (beta) | ||
|
||
[![PyPI version](https://img.shields.io/pypi/v/simple-migrations.svg)](https://pypi.org/project/simple-migrations) | ||
[![Python versions](https://img.shields.io/pypi/pyversions/simple-migrations.svg)](https://pypi.org/project/simple-migrations) | ||
|
||
### Please, notice that the library is early in the development, use it at your own risk. The feedback and contributions are appreciated! | ||
|
||
Make your database migrations as simple as possible! | ||
|
||
`simple-migrations` is a library that allows you to write database migrations in a pure SQL. | ||
|
||
The order of migrations will be tracked in the database table. | ||
|
||
You can specify the `forwards` and `backwards` command and even write your own scripts. | ||
|
||
No need to apply the scripts manually, you can now automate your deployment flow! | ||
|
||
Keep in mind that the library is still in development and is distributed "as is". | ||
|
||
## How to use | ||
|
||
The example of the config can be found in `simple_migrations.ini` file. | ||
|
||
Create a `simple_migrations.ini` file in the project root and set up the database credentials. | ||
|
||
Run `simple-migrations init` to generate the migrations directory and migrations table. | ||
|
||
Run `simple-migrations generate` to generate the migration file from the template. | ||
|
||
Run `simple-migrations migrate` to apply all unapplied migrations. | ||
|
||
Run `simple-migrations migrate <num>` to migrate or rollback to <num> migration, for example: | ||
|
||
- If the last applied migration was #2, `simple-migrations migrate 4` will apply migrations 3 and 4. | ||
- If the last applied migration was #4, `simple-migrations migrate 2` will rollback migrations 3 and 4. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[simple-migrations] | ||
database_host=localhost | ||
database_port=5432 | ||
database_name=simple | ||
database_user=simple | ||
database_password=simple | ||
migrations_dir=migrations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 3 additions & 5 deletions
8
simple_migrations/setup.py → simple_migrations/initial_setup.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
import psycopg | ||
|
||
from simple_migrations.config import Config | ||
|
||
from simple_migrations.config import simple_migrations_config | ||
|
||
FORWARDS_SQL = "" | ||
BACKWARDS_SQL = "" | ||
|
||
|
||
def forwards() -> None: | ||
config = Config() | ||
config = simple_migrations_config.get() | ||
with psycopg.connect(config.connection_string) as conn: | ||
with conn.cursor() as cur: | ||
cur.execute(FORWARDS_SQL) | ||
|
||
|
||
def backwards() -> None: | ||
config = Config() | ||
config = simple_migrations_config.get() | ||
with psycopg.connect(config.connection_string) as conn: | ||
with conn.cursor() as cur: | ||
cur.execute(BACKWARDS_SQL) |