This repository has been archived by the owner on Jan 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Stepwise migrations, command line tool, status. #14
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f1273f8
Convert to entrypoint/command style.
cam-stitt b489fbd
Get tests passing.
cam-stitt 85a5711
Add tests for filenames.
cam-stitt e3c620d
Update travis to test from tests dir.
cam-stitt b487a42
Remove prog from argv.
cam-stitt 7a306e0
Add init command to generate config folder.
cam-stitt 5bb98b0
Add ability to upgrade all. Update docs.
cam-stitt a38805b
Bump 0.4.0.
cam-stitt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,6 +14,25 @@ Installation is simple using pip: | |
|
||
##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 | ||
|
@@ -35,43 +54,46 @@ An example of a migration file can be found [here](https://github.com/cam-stitt/ | |
|
||
###Running Migrations | ||
|
||
To begin running migrations, add a file at the root of your project and give it a name such as `migrator.py`. Copy and paste the following into the file: | ||
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. | ||
|
||
```python | ||
import argparse | ||
from arnold import main | ||
|
||
parser = argparse.ArgumentParser(description="Perform migrations on the database") | ||
parser.add_argument("direction", help="The direction of the migrations") | ||
parser.add_argument("--fake", action="store_true", default=False, help="Do you want to fake the migrations (not actually run them, but update the migration table)?") | ||
|
||
args = parser.parse_args() | ||
|
||
main( | ||
direction=args.direction, | ||
database=SqliteDatabase('test.db'), | ||
directory="path/to/migrations", | ||
migration_module="path.to.migrations", | ||
fake=args.fake | ||
) | ||
``` | ||
arnold up 1 | ||
``` | ||
|
||
Then, you can just run this from the command line: | ||
The above command will run 1 migration upwards, if available. | ||
|
||
```$ python migrator.py "up"``` | ||
``` | ||
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](https://github.com/cam-stitt/arnold/blob/master/arnold/models.py) 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. | ||
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: | ||
|
||
* *direction* - "up" or "down" - direction to migrate | ||
* *ignored* - list of filenames to ignore (not including extension) | ||
* *database* - the peewee database to connect to | ||
* *directory* - the directory of the migration files eg. path/to/migrations | ||
* *migration_module* - the module of the migrations eg. path.to.migrations | ||
* *print* - should we print details of the migration when run? Defaults to True | ||
```python | ||
from peewee import SqliteDatabase | ||
|
||
database = SqliteDatabase('test.db') | ||
``` | ||
|
||
##Contribute | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be great to have the instructions for running tests. |
||
|
||
|
@@ -90,5 +112,4 @@ The project is licensed under the BSD license. | |
|
||
##Roadmap | ||
|
||
* Migration model configuration | ||
* Command line tool | ||
At this point, I don't have any items on the roadmap. If you have any ideas, please create an issue. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nose is not part of the setup.py, why not just use setuptools with
test
command?https://pythonhosted.org/setuptools/setuptools.html#test-build-package-and-run-a-unittest-suite