METADATA 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. Metadata-Version: 2.2
  2. Name: Flask-Migrate
  3. Version: 4.1.0
  4. Summary: SQLAlchemy database migrations for Flask applications using Alembic.
  5. Author-email: Miguel Grinberg <miguel.grinberg@gmail.com>
  6. License: MIT
  7. Project-URL: Homepage, https://github.com/miguelgrinberg/flask-migrate
  8. Project-URL: Bug Tracker, https://github.com/miguelgrinberg/flask-migrate/issues
  9. Classifier: Environment :: Web Environment
  10. Classifier: Intended Audience :: Developers
  11. Classifier: Programming Language :: Python :: 3
  12. Classifier: License :: OSI Approved :: MIT License
  13. Classifier: Operating System :: OS Independent
  14. Requires-Python: >=3.6
  15. Description-Content-Type: text/markdown
  16. License-File: LICENSE
  17. Requires-Dist: Flask>=0.9
  18. Requires-Dist: Flask-SQLAlchemy>=1.0
  19. Requires-Dist: alembic>=1.9.0
  20. Provides-Extra: dev
  21. Requires-Dist: tox; extra == "dev"
  22. Requires-Dist: flake8; extra == "dev"
  23. Requires-Dist: pytest; extra == "dev"
  24. Provides-Extra: docs
  25. Requires-Dist: sphinx; extra == "docs"
  26. Flask-Migrate
  27. =============
  28. [![Build status](https://github.com/miguelgrinberg/flask-migrate/workflows/build/badge.svg)](https://github.com/miguelgrinberg/flask-migrate/actions)
  29. 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.
  30. Installation
  31. ------------
  32. Install Flask-Migrate with `pip`:
  33. pip install Flask-Migrate
  34. Example
  35. -------
  36. This is an example application that handles database migrations through Flask-Migrate:
  37. ```python
  38. from flask import Flask
  39. from flask_sqlalchemy import SQLAlchemy
  40. from flask_migrate import Migrate
  41. app = Flask(__name__)
  42. app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
  43. db = SQLAlchemy(app)
  44. migrate = Migrate(app, db)
  45. class User(db.Model):
  46. id = db.Column(db.Integer, primary_key=True)
  47. name = db.Column(db.String(128))
  48. ```
  49. With the above application you can create the database or enable migrations if the database already exists with the following command:
  50. $ flask db init
  51. 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.
  52. You can then generate an initial migration:
  53. $ flask db migrate
  54. 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.
  55. Then you can apply the migration to the database:
  56. $ flask db upgrade
  57. Then each time the database models change repeat the `migrate` and `upgrade` commands.
  58. To sync the database in another system just refresh the `migrations` folder from source control and run the `upgrade` command.
  59. To see all the commands that are available run this command:
  60. $ flask db --help
  61. Resources
  62. ---------
  63. - [Documentation](http://flask-migrate.readthedocs.io/en/latest/)
  64. - [pypi](https://pypi.python.org/pypi/Flask-Migrate)
  65. - [Change Log](https://github.com/miguelgrinberg/Flask-Migrate/blob/master/CHANGES.md)