-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_create.py
More file actions
35 lines (27 loc) · 992 Bytes
/
db_create.py
File metadata and controls
35 lines (27 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!flask/bin/python
from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from app import db
from app.models import User
import os.path
#################################################
#
# DATABASE
#
#################################################
# Creating all the tables for the described classes in models
db.create_all()
# Adding the Guest user
guest = User.query.filter_by(email='Guest').first()
if not guest :
user = User(email='Guest', password='')
db.session.add(user)
db.session.commit()
# Creating database (only once)
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
api.create(SQLALCHEMY_MIGRATE_REPO, 'db_repository')
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
#making sure we are using the latest version of our database
else:
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))