command initdatas
This commit is contained in:
parent
ffaff20025
commit
fad008b25d
41
ereuse_devicehub/commands/initdatas.py
Normal file
41
ereuse_devicehub/commands/initdatas.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
from uuid import uuid4
|
||||
|
||||
import click
|
||||
from boltons.urlutils import URL
|
||||
|
||||
from ereuse_devicehub.db import db
|
||||
from ereuse_devicehub.resources.agent.models import Person
|
||||
from ereuse_devicehub.resources.inventory.model import Inventory
|
||||
from ereuse_devicehub.resources.user.models import User
|
||||
|
||||
|
||||
class InitDatas:
|
||||
def __init__(self, app) -> None:
|
||||
super().__init__()
|
||||
self.app = app
|
||||
self.schema = app.config.get('DB_SCHEMA')
|
||||
self.app.cli.command(
|
||||
'initdata', short_help='Save a minimum structure of datas.'
|
||||
)(self.run)
|
||||
|
||||
def run(self):
|
||||
inv = Inventory(
|
||||
id=self.schema,
|
||||
name="usody",
|
||||
tag_provider=URL('http://localhost:8081'),
|
||||
tag_token=uuid4(),
|
||||
org_id=uuid4(),
|
||||
)
|
||||
|
||||
db.session.add(inv)
|
||||
db.session.commit()
|
||||
|
||||
email = 'user@dhub.com'
|
||||
password = '1234'
|
||||
name = 'user'
|
||||
|
||||
user = User(email=email, password=password)
|
||||
user.individuals.add(Person(name=name))
|
||||
db.session.add(user)
|
||||
|
||||
db.session.commit()
|
|
@ -5,20 +5,21 @@ from typing import Type
|
|||
import boltons.urlutils
|
||||
import click
|
||||
import click_spinner
|
||||
import ereuse_devicehub.ereuse_utils.cli
|
||||
from ereuse_devicehub.ereuse_utils.session import DevicehubClient
|
||||
from flask import _app_ctx_stack, g
|
||||
from flask_login import LoginManager, current_user
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
import ereuse_devicehub.ereuse_utils.cli
|
||||
from ereuse_devicehub.auth import Auth
|
||||
from ereuse_devicehub.client import Client, UserClient
|
||||
from ereuse_devicehub.commands.initdatas import InitDatas
|
||||
|
||||
# from ereuse_devicehub.commands.reports import Report
|
||||
from ereuse_devicehub.commands.users import GetToken
|
||||
from ereuse_devicehub.config import DevicehubConfig
|
||||
from ereuse_devicehub.db import db
|
||||
from ereuse_devicehub.dummy.dummy import Dummy
|
||||
from ereuse_devicehub.ereuse_utils.session import DevicehubClient
|
||||
from ereuse_devicehub.resources.device.search import DeviceSearch
|
||||
from ereuse_devicehub.resources.inventory import Inventory, InventoryDef
|
||||
from ereuse_devicehub.resources.user.models import User
|
||||
|
@ -73,6 +74,7 @@ class Devicehub(Teal):
|
|||
self.dummy = Dummy(self)
|
||||
# self.report = Report(self)
|
||||
self.get_token = GetToken(self)
|
||||
self.initdata = InitDatas(self)
|
||||
|
||||
@self.cli.group(
|
||||
short_help='Inventory management.',
|
||||
|
|
|
@ -8,12 +8,11 @@ Create Date: 2020-05-07 10:04:40.269511
|
|||
import citext
|
||||
import sqlalchemy as sa
|
||||
import sqlalchemy_utils
|
||||
from ereuse_devicehub import teal
|
||||
from alembic import context
|
||||
from alembic import op
|
||||
from alembic import context, op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
from ereuse_devicehub.resources.enums import TransferState, Severity
|
||||
from ereuse_devicehub import teal
|
||||
from ereuse_devicehub.resources.enums import Severity, TransferState
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'fbb7e2a0cde0'
|
||||
|
@ -348,6 +347,7 @@ def upgrade():
|
|||
postgresql_using='hash',
|
||||
schema=f'{get_inv()}',
|
||||
)
|
||||
op.execute(f"CREATE SEQUENCE {get_inv()}.device_seq START 1;")
|
||||
op.create_table(
|
||||
'agent',
|
||||
sa.Column(
|
||||
|
|
Reference in a new issue