Giter Club home page Giter Club logo

arnold's Introduction

WARNING! Deprecated

I do not have the capacity to maintain this project. Please feel free to fork the repo and apply your updates there, however I will not be updating this repo any further.

Build Status

#arnold - Migrations for peewee

arnold is a python package to assist in managing migrations for the peewee orm.

A full example application can be viewed at cam-stitt/arnold-example.

##Installation

Installation is simple using pip:

pip install arnold

##Usage

###The arnold_config folder To generate the arnold config folder, run the following command:

arnold init

This will create a directory and fill it with the default content. The directory will look like this:

.
+-- arnold_config
|   +-- __init__.py
|   +-- migrations
|       +-- __init__.py

You can provide an option for a custom folder name by using the --folder option. Note that if you provide a custom folder, you will have to pass the --folder option to all future arnold commands.

###Creating Migrations

Migrations are easy to setup. Simply create a migration folder (with an __init__.py) and then start creating your migrations.

Migrations require two methods. up for creation and down for deletion.

Peewee has the ability to easily perform migrations such as adding a column. See peewee docs.

You must follow the naming convention x_name where x is a number, and name is a name for your personal reference. This will ensure that migrations are run in the correct order. Here is an example of some migration files:

001_initial.py
002_add_admin_to_users.py
003_add_account_table.py

An example of a migration file can be found here.

###Running Migrations

Migrations are run in a stepwise manner. There are two commands available to run migrations in a particular direction. Both of these commands require a number to tell arnold how many migrations you would like to run.

arnold up 1

The above command will run 1 migration upwards, if available.

arnold down 3

The above command will run 3 migrations downwards.

If you pass in a count of 0, arnold will run all migrations that have not yet been run.

arnold up 0

The first time that this is run, the Migration table will be added.

###Status

You can also request the status of the database by running arnold status. It will print the latest migration name and the date that it was completed.

###Configuration

Arnold accepts a number of configuration options to the commands.

  • --folder - The folder to use for configration/migrations.
  • --fake - Add the row to the database without running the migration.

The __init__.py file inside the configuration folder holds the database value. This should be peewee database value. Here is an example __init__.py file:

from peewee import SqliteDatabase

database = SqliteDatabase('test.db')

##Contribute

Ideas or Pull Requests to make this project better are always welcome.

##Support

If you are having issues, please let us know.

##License

The project is licensed under the BSD license.

##Roadmap

At this point, I don't have any items on the roadmap. If you have any ideas, please create an issue.

arnold's People

Contributors

arikfr avatar cam-stitt avatar fprieur avatar jcsaaddupuy avatar paulbooth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

arnold's Issues

Automatic generation of migrations

First off, I'm not sure I can ever trust automatically generated migrations, so please consider this issue a question which is: "Are you planing on adding automatic migration writer ala Django/South?" I do like the lack of work that automation provides, but I also like being forced to get to know my migration by writing them. Anyway, if you ever decide automation is the way to go, I'd love to contribute.

.arnoldrc File

I think it would be really nice to have a .arnoldrc file for specifying common command line flags and values. Some options:

  • Specify the value for --folder. We'd love to put our migrations in migrations/, but specifying the command line argument every time is tedious.
  • Specify the default value for up (e.g., 0).
  • Specify the default value for down (e.g., 1).
  • Specify any other values for future commands that might be added (such as a migration template file).

Nothing fancy here, and can only provide simple command line defaults.

initialize databases in migrations

so we're trying to initialize a fresh mysql install with our migrations we've written for arnold.

when we try to connect with MySQLDatabase

it never works, because MySQLDatabase is demanding that the database exists.

arnold it seems just wants to use a reference to one of these connections.

that fine, except we want to create our databases in the migrations. but to run the migrations we've got to create the database. so we're stuck.

does this make sense? are we doing something

can't add new migrations

arnold lacks an argument to add a new migrations to the folder. this would make the tool really good if i could do

arnold --new-migrations mynewmigration

and it would add the file with proper name and number to the migrations directory

arnold up 0 only works when at 0

Using arnold==0.4.0, running arnold up 0 while at 13, doesn't migrate to 14. Seems to do nothing. The only time arnold up 0 seems to work is on a fresh db, or at migration 0. The docs say

If you pass in a count of 0, arnold will run all migrations that have not yet been run.

Ability to Generate Migrations with an Optional Template

Arnold should have a command, such as: arnold generate my_migration_name that generates a base migration file for easy iteration.

My thoughts on this:

  • The name of the file becomes: $(date)_${migration_name}, but is customizable through an argument.
  • The template used is very generic by default, but specifying a custom template to be used with Jinja is also possible (or Mako, whichever templating language is nicer).
  • The custom template has access to some variables such as:
    • current date
    • migration name
    • full migration file name

Right now we have #26 pending, for creating an initial migration for a model, but there's to aid in creating future migrations for models.

`arnold.exceptions` are shadowing real exceptions

Conside the try-catch block from https://github.com/cam-stitt/arnold/blob/master/arnold/__init__.py#L78

In case of an issue with the migration file that has to be loaded, importlib.import_module will through an exception with a relevant message. Arnold instead will raise it's own exception with no relevance at all: arnold.exceptions.ModuleNotFoundException.

I found this while trying to load a migration with a wrong import. Still, arnold kept telling me that module was not found. 😢

Fail More Gracefully if Migration Files Are Missing

Right now, if you try to do an arnold up and an already migrated file isn't in your file system (because it's, say, in another branch), the command completely fails. It would be nice if we could somehow catch this, warn the user and possibly still procede with the migration.

I'm not real sure how feasible this is, but I do know my devs would love it! While I do know the code a bit, I'm not sure why this Exception is thrown when trying to go up (it makes sense when trying to go down).

Logging instead of printing

Hello,

first of all, thank you very much for this project -- peewee really needed something like this!

I'm using arnold in a program that migrates the database "up" on each start (not using a migrator.py). I'm using the standard logging library to log every important event in the program and would like to log migrations, too.

The problem is that arnold currently simply prints its messages. Most libraries I know don't use print statements to not mess with the output of the user programs as they could have CLIs etc...

Maybe you can offer an option whether to use logging or the print statements? Or get rid of the print statements at all? I think the coloured output looks nice, but it would be more usable this way.

Use logging module

Currently, console output is done with a print statement.

It would be better if arnold would use the logging module and let the calling app decide what and how to log its output.

Migration dependency setup

Should be able to reference the dependency of each migration so that naming conventions are not important. Also assists with larger projects and conflicts of work being done.

This issue was raised in #26.

Code and pypi version mismatch

Hi.

I have a project which have arnold==3.8 as a dependancy.

Today, something break.

It seems that the 3.8 eggs version uploaded on pypi is in reality a 4.0 (they had been uploaded the same day) :

screen shot 2015-07-06 at 18 48 25

screen shot 2015-07-06 at 18 30 44

Also, the code seems not to be consistent with its version number :

# installing the 0.3.8 egg
(sandbox)~/s/sandbox ❯❯❯ easy_install "arnold==0.3.8"
Searching for arnold==0.3.8
Downloading https://pypi.python.org/packages/2.7/a/arnold/arnold-0.3.8-py2.7.egg#md5=23d0231cc35730cb7d9d5ee87baf0a5d
Processing arnold-0.3.8-py2.7.egg
...
>>> from arnold import IGNORED_FILES # should work as in 0.3.8
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name IGNORED_FILES
>>> from arnold import Terminator # but this work, as in 0.4.0
>>> Terminator.IGNORED_FILES
['__init__']

# but here, the version is still 0.3.8
>>> import pkg_resources
>>> pkg_resources.require("arnold")[0].version
'0.3.8'

Query status of a db

It would be nice to have something to query a database for current status.

$ python migrator.py "status" with an output like Migration <name> applied on <time>

--fake parameter

I'm thinking about using arnold and I'd like to get your opinion on how to extend it.

Coming from django I miss a --fake parameter. It could work similar to the "ignored" parameter but put entries into the database.

What do you think?

I extended your migrator.py parser with ignored:

parser.add_argument('--ignored', nargs='+')

...

ignored=args.ignored

I need some sort of a logic to convert the existing installations without problems and a simple command

Allow stepwise migrations

It seems it is only possible to go all the way up or down a migration lane in a folder. I would prefer if I can input how many migrations should be run. Say ./migrator up 5 or so.

Include in-Python access to main API

Hi there,

I had gone through a bunch of work to modify my management tool to take its own CLI args and apply them to this module's main function quite cleanly, but have now discovered that there is no longer any simple internal, in-Python access to this module's functionality. Would it be difficult to introduce a function with a signature like such:

def migrate(database, direction, number=0, name=None, fake=False, module_path=None)

which is similar to the "old way" but still makes feature parity (I think) with the present-day implementation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.