Package: limigrations
Migrationsare a type of version control for databases, used to keep track
of the changes made, and to provide easy maintainability.
In case something goes wrong, ‘rollback’ can be run and it will
revert the database to the previous state.limigrationsprovides basic migrations functionality forsqlite3. It contains a method
for connecting to the database, and functions for migrate
and rollback.Getting startedA migration consist in a Python script (preferably named by datetime of creation)
placed in themigrations directory.
The script should contain an import and a class calledMigrationwhich implementsBaseMigration.from limigrations.migration import BaseMigration

class Migration(BaseMigration):
  def up(self, conn, c):
    pass
  def down(self, conn, c):
    passThere is an examplehere.InstalationInstall the package withpip$ pip install limigrationsor clone this repository and install$ git clone git@github.com:dragosthealex/limigrations.git
$ python setup.py installUsage1. In your project create a directory for migrations$ mkdir my-migrations2. Decide on a name for your database e.g.my-database.db$ touch my-database.db3. Create your first migration using the command-line, then edit theupanddownmethods$ limigrations new --new_migration "users_table" --migrations_dir "my-migrations"Optionally, you can copy theexampleand modifying theupanddownmethods, saving it in your migrations directory.
It’s recommended to name it after the date and time e.g.2017-03-08_12:31Command-Line4a. Run$ limigrations migrate --db_file "my-database.db" --migrations_dir "my-migrations"5a. Done! You should now see the changes written in theupmethod being applied.6a. If something goes wrong and you want to revert, run$ limigrations rollback --db_file "my-database.db" --migrations_dir "my-migrations"7a. You should see the changes written in thedownmethod being applied.OptionsThe following options can be used:$ python -m limigrations -h

usage: limigrations.py [-h] [-d DB_FILE] [-m MIGRATIONS_DIR] [-v] action

positional arguments:
  action                Action to take, can be 'migrate' or 'rollback'

optional arguments:
  -h, --help            show this help message and exit
  -d DB_FILE, --db_file DB_FILE
                        Path to the database file.
  -m MIGRATIONS_DIR, --migrations_dir MIGRATIONS_DIR
                        Path to the migrations directory.
  -v, --verbose         VerboseRuntime4b. Import the limigrations module and run the migrationsfrom limigrations import limigrations

limigrations.migrate('my-database.db', 'my-migrations')5a. If you want to rollback later, run the rollbacklimigrations.rollback('my-database.db', 'my-migrations')6a. If you just want to connect to the databaseconn, c = limigrations.connect_database('my-database.db')TestingAfter cloning the repository, runpython -m unittest -v tests.test_limigrationsThere are two tests, one formigrateand one forrollback.
They create a test migration at runtime, defining theupanddownmethods,
and then call the tested functions. The tests should leave no trace, as the
directories and files are deleted after completion.ContributingFork therepositoryon GitHub.Make a branch off of master and commit your changes to it.Run the tests withunittestEnsure that your name is added to the end of the AUTHORS file using the
formatName <email@domain.com> (url), where the(url)portion is
optional.Submit a Pull Request to the master branch on GitHub.If you’d like to have a development environment, you should create a
virtualenv and then dopip install-e.from within the directory.AuthorsAlex Radu -initial work-www.alexdradu.comLicenseThis project is licensed under the MIT License - see theLICENSE.mdfile for details.