Create schema with SQLAlchemy and stamp as head migration
This commit is contained in:
parent
0849d39d5d
commit
f9858f50ab
|
@ -10,6 +10,7 @@ from ereuse_utils.session import DevicehubClient
|
||||||
from flask.globals import _app_ctx_stack, g
|
from flask.globals import _app_ctx_stack, g
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
from teal.teal import Teal
|
from teal.teal import Teal
|
||||||
|
from teal.db import SchemaSQLAlchemy
|
||||||
|
|
||||||
from ereuse_devicehub.auth import Auth
|
from ereuse_devicehub.auth import Auth
|
||||||
from ereuse_devicehub.client import Client
|
from ereuse_devicehub.client import Client
|
||||||
|
@ -115,6 +116,22 @@ class Devicehub(Teal):
|
||||||
self.db.session.commit()
|
self.db.session.commit()
|
||||||
print('done.')
|
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 {}?'
|
@click.confirmation_option(prompt='Are you sure you want to delete the inventory {}?'
|
||||||
.format(os.environ.get('dhi')))
|
.format(os.environ.get('dhi')))
|
||||||
def delete_inventory(self):
|
def delete_inventory(self):
|
||||||
|
|
|
@ -7,6 +7,9 @@ Create Date: ${create_date}
|
||||||
"""
|
"""
|
||||||
from alembic import op
|
from alembic import op
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
import sqlalchemy_utils
|
||||||
|
import citext
|
||||||
|
import teal
|
||||||
${imports if imports else ""}
|
${imports if imports else ""}
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
|
|
File diff suppressed because one or more lines are too long
Reference in New Issue