-
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.
Introduced the official version 1.0.0 of Mongrations! Refer to change…
…log in README.md
- Loading branch information
Showing
19 changed files
with
417 additions
and
309 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 |
---|---|---|
|
@@ -14,5 +14,6 @@ old.txt | |
docs/_build/** | ||
docs/_templates/** | ||
migrations/** | ||
.mongrations/** | ||
.DS_Store | ||
mongrations/data/cache.json |
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
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
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,20 @@ | ||
from mongrations import Mongrations, Database | ||
from pydotenvs import load_env, load_env_object | ||
|
||
load_env('.env-example') # by default it looks for .env in the current directory | ||
# config = load_env_object() # connect via dictionary of environment variables [ i.e Mongrations(config) ] | ||
|
||
|
||
class Mongration(Database): | ||
def __init__(self): | ||
super(Database, self).__init__() | ||
|
||
def up(self): | ||
raw_sql = "ALTER TABLE users ADD gender NVARCHAR" | ||
self.raw(raw_sql) | ||
|
||
def down(self): | ||
self.drop_table('users') | ||
|
||
|
||
Mongrations(Mongration, db_service='mysql') # raw can be used with all three supported DBs (i.e. MySQL, MongoDB & Postgres) |
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,4 +1,11 @@ | ||
from mongrations.main import Mongrations, MongrationsCli, Database | ||
from mongrations.version import __version__ | ||
try: | ||
from mongrations.main import Mongrations, MongrationsCli | ||
from mongrations.database import Database | ||
from mongrations.version import __version__ | ||
except ImportError: | ||
from .main import Mongrations, MongrationsCli | ||
from .database import Database | ||
from .version import __version__ | ||
|
||
__all__ = [Mongrations, Mongrations, __version__, Database] | ||
|
||
__all__ = [Mongrations, MongrationsCli, Database, __version__] |
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,38 +1,51 @@ | ||
import click, sys | ||
from mongrations.main import MongrationsCli | ||
from mongrations.version import __version__ | ||
|
||
|
||
@click.command('mongrations') | ||
@click.option('-M', '--migrate', default=False, type=click.BOOL, | ||
help='Run migrations') | ||
@click.option('-C', '--create', default=False, type=click.BOOL, | ||
help='Create new migration') | ||
@click.option('-N', '--name', default='-no-name-migration', type=click.STRING, | ||
help='Name for newly created migration') | ||
@click.option('--directory', default='migrations', type=click.STRING, | ||
help='File path for newly created migration') | ||
@click.option('-U', '--undo', default=False, type=click.BOOL, | ||
help='Undo last migration') | ||
@click.option('-D', '--down', default=False, type=click.BOOL, | ||
help='Revert database') | ||
try: | ||
from mongrations.main import MongrationsCli | ||
from mongrations.version import __version__ | ||
except Exception: | ||
from .main import MongrationsCli | ||
from .version import __version__ | ||
|
||
main = MongrationsCli() | ||
|
||
@click.group() | ||
@click.version_option(version=__version__) | ||
def mongrations(migrate, create, name, directory, undo, down): | ||
main = MongrationsCli() | ||
try: | ||
if migrate: | ||
main.migrate() | ||
if create: | ||
main.create(directory=directory, name=name) | ||
if undo: | ||
main.undo() | ||
if down: | ||
main.down() | ||
except Exception as e: | ||
print(e) | ||
finally: | ||
sys.exit() | ||
def cli(): | ||
"""Mongrations; a database migration tool for Python 3.6 and above.""" | ||
pass | ||
|
||
|
||
@cli.command() | ||
def migrate(): | ||
main.migrate() | ||
|
||
|
||
@cli.command() | ||
@click.argument('name', nargs=1) | ||
@click.argument('directory', nargs=-1) | ||
def create(name, directory): | ||
if len(directory) == 0: | ||
directory = 'migrations' | ||
|
||
if len(name) == 0: | ||
name = 'no-name-migration' | ||
main.create(directory=directory, name=name) | ||
|
||
|
||
@cli.command() | ||
def undo(): | ||
main.undo() | ||
|
||
|
||
@cli.command() | ||
def down(): | ||
main.down() | ||
|
||
|
||
@cli.command() | ||
def inspect(): | ||
main.inspector() | ||
|
||
|
||
if __name__ == '__main__': | ||
mongrations() | ||
cli() |
Oops, something went wrong.