Add migrations with Flask-Migrate

master
Steven Loria 11 years ago
parent 65527129f9
commit 64e28cfdaa
  1. 23
      README.rst
  2. 23
      {{cookiecutter.repo_name}}/README.rst
  3. 3
      {{cookiecutter.repo_name}}/manage.py
  4. 3
      {{cookiecutter.repo_name}}/requirements/prod.txt
  5. 5
      {{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/app.py
  6. 3
      {{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/extensions.py

@ -5,11 +5,21 @@ A Flask template for cookiecutter_.
.. _cookiecutter: https://github.com/audreyr/cookiecutter .. _cookiecutter: https://github.com/audreyr/cookiecutter
Use it now
----------
::
$ pip install cookiecutter
$ cookiecutter https://github.com/sloria/cookiecutter-flask.git
You will be asked about your basic info (name, project name, etc.). This info will be used in your new project.
Features Features
-------- --------
- Twitter Bootstrap 3 and starter templates - Twitter Bootstrap 3 and starter templates
- Flask-SQLAlchemy with basic User model - Flask-SQLAlchemy with basic User model
- Easy database migrations with Flask-Migrate
- Flask-WTForms with login and registration forms - Flask-WTForms with login and registration forms
- Flask-Login for authentication - Flask-Login for authentication
- Procfile for deploying to a PaaS (e.g. Heroku) - Procfile for deploying to a PaaS (e.g. Heroku)
@ -30,19 +40,7 @@ Screenshots
:target: https://dl.dropboxusercontent.com/u/1693233/github/cookiecutter-flask-02.png.png :target: https://dl.dropboxusercontent.com/u/1693233/github/cookiecutter-flask-02.png.png
:alt: Registration form :alt: Registration form
Using this template
-------------------
::
$ pip install cookiecutter
$ cookiecutter https://github.com/sloria/cookiecutter-flask.git
You will be asked about your basic info (name, project name, etc.). This info will be used in your new project.
Blueprints? App factories?
--------------------------
If you prefer not to use blueprints or an application factory, check out the ``simple`` branch which has the older structure without these patterns. Note, however, only the ``master`` branch will be actively maintained.
Inspiration Inspiration
----------- -----------
@ -74,6 +72,7 @@ Changelog
- Use Factory-Boy for test factories. - Use Factory-Boy for test factories.
- Use WebTest for functional testing. - Use WebTest for functional testing.
- Add Flask-Debugtoolbar. - Add Flask-Debugtoolbar.
- Migrations using Flask-Migrate.
0.2.0 (09/21/2013) 0.2.0 (09/21/2013)
****************** ******************

@ -13,10 +13,13 @@ Quickstart
git clone https://github.com/{{cookiecutter.github_username}}/{{ cookiecutter.repo_name }} git clone https://github.com/{{cookiecutter.github_username}}/{{ cookiecutter.repo_name }}
cd {{cookiecutter.repo_name}} cd {{cookiecutter.repo_name}}
pip install -r requirements/dev.txt pip install -r requirements/dev.txt
python manage.py createdb python manage.py db init
python manage.py db migrate
python manage.py db upgrade
python manage.py server python manage.py server
Deployment Deployment
---------- ----------
@ -39,3 +42,21 @@ Running Tests
To run all tests, run :: To run all tests, run ::
python manage.py test python manage.py test
Migrations
----------
Whenever a database migration needs to be made. Run the following commmands:
::
python manage.py db migrate
This will generate a new migration script. Then run:
::
python manage.py db upgrade
To apply the migration.
For a full migration command reference, run ``python manage.py db --help``.

@ -4,6 +4,8 @@ import os
import sys import sys
import subprocess import subprocess
from flask.ext.script import Manager, Shell, Server from flask.ext.script import Manager, Shell, Server
from flask.ext.migrate import MigrateCommand
from {{cookiecutter.repo_name}}.app import create_app from {{cookiecutter.repo_name}}.app import create_app
from {{cookiecutter.repo_name}}.settings import DevConfig, ProdConfig from {{cookiecutter.repo_name}}.settings import DevConfig, ProdConfig
from {{cookiecutter.repo_name}}.database import db from {{cookiecutter.repo_name}}.database import db
@ -35,6 +37,7 @@ def createdb():
manager.add_command("server", Server()) manager.add_command("server", Server())
manager.add_command("shell", Shell(make_context=_make_context)) manager.add_command("shell", Shell(make_context=_make_context))
manager.add_command('db', MigrateCommand)
if __name__ == '__main__': if __name__ == '__main__':
manager.run() manager.run()

@ -11,6 +11,9 @@ itsdangerous==0.23
Flask-SQLAlchemy==1.0 Flask-SQLAlchemy==1.0
SQLAlchemy==0.8.3 SQLAlchemy==0.8.3
# Migrations
Flask-Migrate>=1.0.0
# Forms # Forms
Flask-WTF==0.9.3 Flask-WTF==0.9.3
WTForms==1.0.5 WTForms==1.0.5

@ -1,12 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from flask import Flask from flask import Flask
from flask.ext.assets import Environment
from flask_debugtoolbar import DebugToolbarExtension from flask_debugtoolbar import DebugToolbarExtension
from webassets.loaders import PythonLoader
from {{cookiecutter.repo_name}}.settings import ProdConfig from {{cookiecutter.repo_name}}.settings import ProdConfig
from {{cookiecutter.repo_name}}.assets import assets from {{cookiecutter.repo_name}}.assets import assets
from {{cookiecutter.repo_name}}.extensions import db, login_manager from {{cookiecutter.repo_name}}.extensions import db, login_manager, migrate
from {{cookiecutter.repo_name}} import public, user from {{cookiecutter.repo_name}} import public, user
@ -28,6 +26,7 @@ def register_extensions(app):
login_manager.init_app(app) login_manager.init_app(app)
assets.init_app(app) assets.init_app(app)
toolbar = DebugToolbarExtension(app) toolbar = DebugToolbarExtension(app)
migrate.init_app(app, db)
return None return None

@ -9,3 +9,6 @@ login_manager = LoginManager()
from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.sqlalchemy import SQLAlchemy
db = SQLAlchemy() db = SQLAlchemy()
from flask.ext.migrate import Migrate
migrate = Migrate()

Loading…
Cancel
Save