Skip to content

Instantly share code, notes, and snippets.

@anshumanv
Created November 26, 2017 13:20
Show Gist options
  • Save anshumanv/66f6c27385fe0f54bcf581a5192645ef to your computer and use it in GitHub Desktop.
Save anshumanv/66f6c27385fe0f54bcf581a5192645ef to your computer and use it in GitHub Desktop.
Generic python script to init a SQLAlchemy Database in Flask
#!flask/bin/python
from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from app import db
import os.path
db.create_all()
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
else:
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment