All Projects → miguelgrinberg → Flask Migrate

miguelgrinberg / Flask Migrate

Licence: mit
SQLAlchemy database migrations for Flask applications using Alembic

Programming Languages

python
139335 projects - #7 most used programming language
Mako
254 projects

Projects that are alternatives of or similar to Flask Migrate

Zero downtime migrations
Zero downtime migrations with ActiveRecord 3+ and PostgreSQL
Stars: ✭ 513 (-73.97%)
Mutual labels:  migrations, database
Doctrinemigrations
[DEPRECATED] Use Phinx instead
Stars: ✭ 24 (-98.78%)
Mutual labels:  migrations, database
Ragtime
Database-independent migration library
Stars: ✭ 519 (-73.67%)
Mutual labels:  migrations, database
flask-db
A Flask CLI extension to help migrate and manage your SQL database.
Stars: ✭ 56 (-97.16%)
Mutual labels:  migrations, alembic
Shorty
🔗 A URL shortening service built using Flask and MySQL
Stars: ✭ 78 (-96.04%)
Mutual labels:  database, flask
Etlalchemy
Extract, Transform, Load: Any SQL Database in 4 lines of Code.
Stars: ✭ 460 (-76.66%)
Mutual labels:  migrations, database
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 7,712 (+291.27%)
Mutual labels:  migrations, database
Laravel Migrate Fresh
An artisan command to build up a database from scratch
Stars: ✭ 179 (-90.92%)
Mutual labels:  migrations, database
Sqlite Web
Web-based SQLite database browser written in Python
Stars: ✭ 1,169 (-40.69%)
Mutual labels:  database, flask
Migration
Simple and pragmatic migrations for Go applications.
Stars: ✭ 66 (-96.65%)
Mutual labels:  migrations, database
apistar alembic migrations
Alembic migrations for apistar
Stars: ✭ 18 (-99.09%)
Mutual labels:  migrations, alembic
Get Started Python
A Python application and tutorial that use Flask framework to provide a REST API to receive requests from the UI. The API then persists the data to a Cloudant database.
Stars: ✭ 104 (-94.72%)
Mutual labels:  database, flask
Django Migration Linter
🚀 Detect backward incompatible migrations for your django project
Stars: ✭ 231 (-88.28%)
Mutual labels:  migrations, database
Migrate Mongo
A database migration tool for MongoDB in Node
Stars: ✭ 481 (-75.6%)
Mutual labels:  migrations, database
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 2,315 (+17.45%)
Mutual labels:  migrations, database
Node Sqlite
SQLite client for Node.js applications with SQL-based migrations API written in Typescript
Stars: ✭ 642 (-67.43%)
Mutual labels:  migrations, database
Express Typescript Boilerplate
A delightful way to building a RESTful API with NodeJs & TypeScript by @w3tecch
Stars: ✭ 2,293 (+16.34%)
Mutual labels:  migrations, database
Postgres Migrations
🐦 A Stack Overflow-inspired PostgreSQL migration library with strict ordering and immutable migrations
Stars: ✭ 161 (-91.83%)
Mutual labels:  migrations, database
Node Pg Migrate
Node.js database migration management for Postgresql
Stars: ✭ 838 (-57.48%)
Mutual labels:  migrations, database
Lol dba
lol_dba is a small package of rake tasks that scan your application models and displays a list of columns that probably should be indexed. Also, it can generate .sql migration scripts.
Stars: ✭ 1,363 (-30.85%)
Mutual labels:  migrations, database

Flask-Migrate

Build status

Flask-Migrate is an extension that handles SQLAlchemy database migrations for Flask applications using Alembic. The database operations are provided as command-line arguments under the flask db command.

Installation

Install Flask-Migrate with pip:

pip install Flask-Migrate

Example

This is an example application that handles database migrations through Flask-Migrate:

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'

db = SQLAlchemy(app)
migrate = Migrate(app, db)

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(128))

With the above application you can create the database or enable migrations if the database already exists with the following command:

$ flask db init

Note that the FLASK_APP environment variable must be set according to the Flask documentation for this command to work. This will add a migrations folder to your application. The contents of this folder need to be added to version control along with your other source files.

You can then generate an initial migration:

$ flask db migrate

The migration script needs to be reviewed and edited, as Alembic currently does not detect every change you make to your models. In particular, Alembic is currently unable to detect indexes. Once finalized, the migration script also needs to be added to version control.

Then you can apply the migration to the database:

$ flask db upgrade

Then each time the database models change repeat the migrate and upgrade commands.

To sync the database in another system just refresh the migrations folder from source control and run the upgrade command.

To see all the commands that are available run this command:

$ flask db --help

Resources

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].