Flask-Migrate


NameFlask-Migrate JSON
Version 4.0.7 PyPI version JSON
download
home_page
SummarySQLAlchemy database migrations for Flask applications using Alembic.
upload_time2024-03-11 18:43:01
maintainer
docs_urlhttps://pythonhosted.org/Flask-Migrate/
author
requires_python>=3.6
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Flask-Migrate
=============

[![Build status](https://github.com/miguelgrinberg/flask-migrate/workflows/build/badge.svg)](https://github.com/miguelgrinberg/flask-migrate/actions)

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:

```python
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
---------

- [Documentation](http://flask-migrate.readthedocs.io/en/latest/)
- [pypi](https://pypi.python.org/pypi/Flask-Migrate) 
- [Change Log](https://github.com/miguelgrinberg/Flask-Migrate/blob/master/CHANGES.md)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "Flask-Migrate",
    "maintainer": "",
    "docs_url": "https://pythonhosted.org/Flask-Migrate/",
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "Miguel Grinberg <miguel.grinberg@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/3b/e2/4008fc0d298d7ce797021b194bbe151d4d12db670691648a226d4fc8aefc/Flask-Migrate-4.0.7.tar.gz",
    "platform": null,
    "description": "Flask-Migrate\n=============\n\n[![Build status](https://github.com/miguelgrinberg/flask-migrate/workflows/build/badge.svg)](https://github.com/miguelgrinberg/flask-migrate/actions)\n\nFlask-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.\n\nInstallation\n------------\n\nInstall Flask-Migrate with `pip`:\n\n    pip install Flask-Migrate\n\nExample\n-------\n\nThis is an example application that handles database migrations through Flask-Migrate:\n\n```python\nfrom flask import Flask\nfrom flask_sqlalchemy import SQLAlchemy\nfrom flask_migrate import Migrate\n\napp = Flask(__name__)\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'\n\ndb = SQLAlchemy(app)\nmigrate = Migrate(app, db)\n\nclass User(db.Model):\n    id = db.Column(db.Integer, primary_key=True)\n    name = db.Column(db.String(128))\n```\n\nWith the above application you can create the database or enable migrations if the database already exists with the following command:\n\n    $ flask db init\n\nNote 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. \n\nYou can then generate an initial migration:\n\n    $ flask db migrate\n    \nThe 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.\n\nThen you can apply the migration to the database:\n\n    $ flask db upgrade\n    \nThen each time the database models change repeat the `migrate` and `upgrade` commands.\n\nTo sync the database in another system just refresh the `migrations` folder from source control and run the `upgrade` command.\n\nTo see all the commands that are available run this command:\n\n    $ flask db --help\n\nResources\n---------\n\n- [Documentation](http://flask-migrate.readthedocs.io/en/latest/)\n- [pypi](https://pypi.python.org/pypi/Flask-Migrate) \n- [Change Log](https://github.com/miguelgrinberg/Flask-Migrate/blob/master/CHANGES.md)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "SQLAlchemy database migrations for Flask applications using Alembic.",
    "version": "4.0.7",
    "project_urls": {
        "Bug Tracker": "https://github.com/miguelgrinberg/flask-migrate/issues",
        "Homepage": "https://github.com/miguelgrinberg/flask-migrate"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9301587023575286236f95d2ab8a826c320375ed5ea2102bb103ed89704ffa6b",
                "md5": "2860c09a26a203c7376b4a6282788685",
                "sha256": "5c532be17e7b43a223b7500d620edae33795df27c75811ddf32560f7d48ec617"
            },
            "downloads": -1,
            "filename": "Flask_Migrate-4.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2860c09a26a203c7376b4a6282788685",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 21127,
            "upload_time": "2024-03-11T18:42:59",
            "upload_time_iso_8601": "2024-03-11T18:42:59.462298Z",
            "url": "https://files.pythonhosted.org/packages/93/01/587023575286236f95d2ab8a826c320375ed5ea2102bb103ed89704ffa6b/Flask_Migrate-4.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3be24008fc0d298d7ce797021b194bbe151d4d12db670691648a226d4fc8aefc",
                "md5": "eaeddc08bcc2f1910647ff246e597bff",
                "sha256": "dff7dd25113c210b069af280ea713b883f3840c1e3455274745d7355778c8622"
            },
            "downloads": -1,
            "filename": "Flask-Migrate-4.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "eaeddc08bcc2f1910647ff246e597bff",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 21770,
            "upload_time": "2024-03-11T18:43:01",
            "upload_time_iso_8601": "2024-03-11T18:43:01.498853Z",
            "url": "https://files.pythonhosted.org/packages/3b/e2/4008fc0d298d7ce797021b194bbe151d4d12db670691648a226d4fc8aefc/Flask-Migrate-4.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-11 18:43:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "miguelgrinberg",
    "github_project": "flask-migrate",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "flask-migrate"
}
        
Elapsed time: 0.62075s