Create schema with SQLAlchemy and stamp as head migration

This commit is contained in:
yiorgos marinellis 2020-05-11 10:07:23 +02:00
parent 0849d39d5d
commit f9858f50ab
3 changed files with 20 additions and 853 deletions

View File

@ -10,6 +10,7 @@ from ereuse_utils.session import DevicehubClient
from flask.globals import _app_ctx_stack, g
from flask_sqlalchemy import SQLAlchemy
from teal.teal import Teal
from teal.db import SchemaSQLAlchemy
from ereuse_devicehub.auth import Auth
from ereuse_devicehub.client import Client
@ -115,6 +116,22 @@ class Devicehub(Teal):
self.db.session.commit()
print('done.')
def _init_db(self, exclude_schema=None) -> bool:
if exclude_schema:
assert isinstance(self.db, SchemaSQLAlchemy)
self.db.create_all(exclude_schema=exclude_schema)
else:
self.db.create_all()
from alembic.config import Config
from alembic import command
alembic_cfg = Config('alembic.ini')
command.stamp(alembic_cfg, "head")
return True
@click.confirmation_option(prompt='Are you sure you want to delete the inventory {}?'
.format(os.environ.get('dhi')))
def delete_inventory(self):

View File

@ -7,6 +7,9 @@ Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
import sqlalchemy_utils
import citext
import teal
${imports if imports else ""}
# revision identifiers, used by Alembic.

File diff suppressed because one or more lines are too long