Update Access Key ORM
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 04f3fe65d40b
|
||||
Revision ID: 23baf9256373
|
||||
Revises:
|
||||
Create Date: 2022-07-12 07:03:12.713616
|
||||
Create Date: 2022-07-12 10:51:54.236220
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
@@ -10,7 +10,7 @@ import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '04f3fe65d40b'
|
||||
revision = '23baf9256373'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
@@ -51,12 +51,12 @@ def upgrade():
|
||||
)
|
||||
op.create_table('lists',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('accessKey', sa.String(length=64), nullable=True),
|
||||
sa.Column('key', sa.String(length=64), nullable=True),
|
||||
sa.Column('name', sa.String(length=128), nullable=False),
|
||||
sa.Column('notes', sa.String(), nullable=True),
|
||||
sa.Column('createdAt', sa.DateTime(), nullable=True),
|
||||
sa.Column('modifiedAt', sa.DateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['accessKey'], ['access_keys.key'], ),
|
||||
sa.ForeignKeyConstraint(['key'], ['access_keys.key'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('products',
|
||||
@@ -29,6 +29,16 @@ def init_orm():
|
||||
|
||||
# Access Keys
|
||||
db.mapper(AccessKey, access_keys, properties={
|
||||
'lists': db.relationship(
|
||||
ShoppingList,
|
||||
back_populates='accessKey',
|
||||
cascade='all, delete-orphan',
|
||||
),
|
||||
'products': db.relationship(
|
||||
Product,
|
||||
back_populates='accessKey',
|
||||
cascade='all, delete-orphan',
|
||||
),
|
||||
'tokens': db.relationship(
|
||||
AccessToken,
|
||||
back_populates='accessKey',
|
||||
@@ -58,6 +68,10 @@ def init_orm():
|
||||
|
||||
# Products
|
||||
db.mapper(Product, products, properties={
|
||||
'accessKey': db.relationship(
|
||||
AccessKey,
|
||||
back_populates='products'
|
||||
),
|
||||
'entries': db.relationship(
|
||||
ListEntry,
|
||||
back_populates='product',
|
||||
@@ -80,6 +94,10 @@ def init_orm():
|
||||
|
||||
# Shopping Lists
|
||||
db.mapper(ShoppingList, lists, properties={
|
||||
'accessKey': db.relationship(
|
||||
AccessKey,
|
||||
back_populates='lists'
|
||||
),
|
||||
'entries': db.relationship(
|
||||
ListEntry,
|
||||
back_populates='shoppingList',
|
||||
|
||||
@@ -68,7 +68,7 @@ lists = db.Table(
|
||||
db.Column('id', db.Integer, primary_key=True),
|
||||
|
||||
# Access Key
|
||||
db.Column('accessKey', db.ForeignKey('access_keys.key'), default=None),
|
||||
db.Column('key', db.ForeignKey('access_keys.key'), default=None),
|
||||
|
||||
# List Attributes
|
||||
db.Column('name', db.String(128), nullable=False),
|
||||
|
||||
@@ -6,7 +6,11 @@ Copyright (c) 2022 Asymworks, LLC. All Rights Reserved.
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
from typing import List, TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .list import ShoppingList
|
||||
from .product import Product
|
||||
|
||||
__all__ = ('AccessKey', 'AccessToken')
|
||||
|
||||
@@ -42,6 +46,8 @@ class AccessKey:
|
||||
restoredAt: datetime = None
|
||||
|
||||
# Relationship Fields
|
||||
lists: List['ShoppingList'] = field(default_factory=list)
|
||||
products: List['Product'] = field(default_factory=list)
|
||||
tokens: List['AccessToken'] = field(default_factory=list)
|
||||
|
||||
|
||||
|
||||
@@ -133,6 +133,10 @@ def create_app(app_config=None, app_name=None):
|
||||
from .socketio import init_socketio
|
||||
init_socketio(app)
|
||||
|
||||
# Initialize Frontend
|
||||
from .frontend import init_frontend
|
||||
init_frontend(app)
|
||||
|
||||
# Startup Complete
|
||||
app.logger.info('{} startup complete'.format(app.config['APP_NAME']))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user