Infrastructure to build the worker docker and run it.

This commit is contained in:
2020-10-14 08:19:42 +05:30
parent 99f5f09c17
commit fc6eebed19
10 changed files with 267 additions and 88 deletions

5
.env
View File

@ -5,10 +5,7 @@ DEBUG=true
SQLALCHEMY_DATABASE_URI= SQLALCHEMY_DATABASE_URI=
MODULE_NAME=barker.main MODULE_NAME=barker.main
PROJECT_NAME=barker PROJECT_NAME=barker
POSTGRES_SERVER= RABBITMQ_URI=
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_DB=
# openssl rand -hex 32 # openssl rand -hex 32
SECRET_KEY= SECRET_KEY=

View File

@ -1,10 +1,9 @@
import logging import logging
from sqlalchemy import create_engine
from sqlalchemy import pool
from alembic import context from alembic import context
from barker.core.config import settings from barker.core.config import settings
from sqlalchemy import create_engine, pool
logging.basicConfig() logging.basicConfig()
logging.getLogger("sqlalchemy.engine").setLevel(settings.ALEMBIC_LOG_LEVEL) logging.getLogger("sqlalchemy.engine").setLevel(settings.ALEMBIC_LOG_LEVEL)
@ -15,6 +14,7 @@ logging.getLogger("alembic").setLevel(settings.ALEMBIC_LOG_LEVEL)
from barker.models.auth import User # noqa from barker.models.auth import User # noqa
target_metadata = User.metadata target_metadata = User.metadata
# other values from the config, defined by the needs of env.py, # other values from the config, defined by the needs of env.py,
@ -55,10 +55,15 @@ def run_migrations_online():
and associate a connection with the context. and associate a connection with the context.
""" """
connectable = create_engine(settings.SQLALCHEMY_DATABASE_URI, poolclass=pool.NullPool,) connectable = create_engine(
settings.SQLALCHEMY_DATABASE_URI,
poolclass=pool.NullPool,
)
with connectable.connect() as connection: with connectable.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata, compare_type=True) context.configure(
connection=connection, target_metadata=target_metadata, compare_type=True
)
with context.begin_transaction(): with context.begin_transaction():
context.run_migrations() context.run_migrations()

View File

@ -7,12 +7,13 @@ Create Date: 2020-06-04 08:14:34.132248
""" """
import uuid import uuid
from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op
from barker.models import Customer, DbSetting, ModifierCategory, Section, SettleOption
from barker.models.auth import Permission, User # noqa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
from barker.models import Section, ModifierCategory, SettleOption, Customer, DbSetting
from barker.models.auth import User, Permission # noqa
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = "8c06ac60d125" revision = "8c06ac60d125"
@ -137,7 +138,9 @@ def upgrade():
sa.Column("id", postgresql.UUID(), nullable=False), sa.Column("id", postgresql.UUID(), nullable=False),
sa.Column("name", sa.Unicode(length=255), nullable=False), sa.Column("name", sa.Unicode(length=255), nullable=False),
sa.Column("section_id", postgresql.UUID(), nullable=False), sa.Column("section_id", postgresql.UUID(), nullable=False),
sa.ForeignKeyConstraint(["section_id"], ["sections.id"], name=op.f("fk_devices_section_id_sections")), sa.ForeignKeyConstraint(
["section_id"], ["sections.id"], name=op.f("fk_devices_section_id_sections")
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_devices")), sa.PrimaryKeyConstraint("id", name=op.f("pk_devices")),
sa.UniqueConstraint("name", name=op.f("uq_devices_name")), sa.UniqueConstraint("name", name=op.f("uq_devices_name")),
) )
@ -149,7 +152,11 @@ def upgrade():
sa.Column("section_id", postgresql.UUID(), nullable=False), sa.Column("section_id", postgresql.UUID(), nullable=False),
sa.Column("is_active", sa.Boolean(), nullable=False), sa.Column("is_active", sa.Boolean(), nullable=False),
sa.Column("sort_order", sa.Numeric(), nullable=False), sa.Column("sort_order", sa.Numeric(), nullable=False),
sa.ForeignKeyConstraint(["section_id"], ["sections.id"], name=op.f("fk_food_tables_section_id_sections")), sa.ForeignKeyConstraint(
["section_id"],
["sections.id"],
name=op.f("fk_food_tables_section_id_sections"),
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_food_tables")), sa.PrimaryKeyConstraint("id", name=op.f("pk_food_tables")),
sa.UniqueConstraint("name", name=op.f("uq_food_tables_name")), sa.UniqueConstraint("name", name=op.f("uq_food_tables_name")),
) )
@ -159,7 +166,11 @@ def upgrade():
sa.Column("customer_id", postgresql.UUID(), nullable=False), sa.Column("customer_id", postgresql.UUID(), nullable=False),
sa.Column("pax", sa.Numeric(), nullable=False), sa.Column("pax", sa.Numeric(), nullable=False),
sa.Column("creation_date", sa.DateTime(timezone=True), nullable=False), sa.Column("creation_date", sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(["customer_id"], ["customers.id"], name=op.f("fk_guest_book_customer_id_customers")), sa.ForeignKeyConstraint(
["customer_id"],
["customers.id"],
name=op.f("fk_guest_book_customer_id_customers"),
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_guest_book")), sa.PrimaryKeyConstraint("id", name=op.f("pk_guest_book")),
) )
op.create_table( op.create_table(
@ -184,18 +195,26 @@ def upgrade():
sa.Column("permission_id", postgresql.UUID(), nullable=False), sa.Column("permission_id", postgresql.UUID(), nullable=False),
sa.Column("role_id", postgresql.UUID(), nullable=False), sa.Column("role_id", postgresql.UUID(), nullable=False),
sa.ForeignKeyConstraint( sa.ForeignKeyConstraint(
["permission_id"], ["permissions.id"], name=op.f("fk_role_permissions_permission_id_permissions") ["permission_id"],
["permissions.id"],
name=op.f("fk_role_permissions_permission_id_permissions"),
),
sa.ForeignKeyConstraint(
["role_id"], ["roles.id"], name=op.f("fk_role_permissions_role_id_roles")
), ),
sa.ForeignKeyConstraint(["role_id"], ["roles.id"], name=op.f("fk_role_permissions_role_id_roles")),
sa.PrimaryKeyConstraint("id", name=op.f("pk_role_permissions")), sa.PrimaryKeyConstraint("id", name=op.f("pk_role_permissions")),
sa.UniqueConstraint("permission_id", "role_id", name=op.f("uq_role_permissions_permission_id")), sa.UniqueConstraint(
"permission_id", "role_id", name=op.f("uq_role_permissions_permission_id")
),
) )
op.create_table( op.create_table(
"sale_categories", "sale_categories",
sa.Column("id", postgresql.UUID(), nullable=False), sa.Column("id", postgresql.UUID(), nullable=False),
sa.Column("name", sa.Unicode(length=255), nullable=False), sa.Column("name", sa.Unicode(length=255), nullable=False),
sa.Column("tax_id", postgresql.UUID(), nullable=False), sa.Column("tax_id", postgresql.UUID(), nullable=False),
sa.ForeignKeyConstraint(["tax_id"], ["taxes.id"], name=op.f("fk_sale_categories_tax_id_taxes")), sa.ForeignKeyConstraint(
["tax_id"], ["taxes.id"], name=op.f("fk_sale_categories_tax_id_taxes")
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_sale_categories")), sa.PrimaryKeyConstraint("id", name=op.f("pk_sale_categories")),
sa.UniqueConstraint("name", name=op.f("uq_sale_categories_name")), sa.UniqueConstraint("name", name=op.f("uq_sale_categories_name")),
) )
@ -211,18 +230,34 @@ def upgrade():
["menu_categories.id"], ["menu_categories.id"],
name=op.f("fk_section_printers_menu_category_id_menu_categories"), name=op.f("fk_section_printers_menu_category_id_menu_categories"),
), ),
sa.ForeignKeyConstraint(["printer_id"], ["printers.id"], name=op.f("fk_section_printers_printer_id_printers")), sa.ForeignKeyConstraint(
sa.ForeignKeyConstraint(["section_id"], ["sections.id"], name=op.f("fk_section_printers_section_id_sections")), ["printer_id"],
["printers.id"],
name=op.f("fk_section_printers_printer_id_printers"),
),
sa.ForeignKeyConstraint(
["section_id"],
["sections.id"],
name=op.f("fk_section_printers_section_id_sections"),
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_section_printers")), sa.PrimaryKeyConstraint("id", name=op.f("pk_section_printers")),
sa.UniqueConstraint("menu_category_id", "section_id", name=op.f("uq_section_printers_menu_category_id")), sa.UniqueConstraint(
"menu_category_id",
"section_id",
name=op.f("uq_section_printers_menu_category_id"),
),
) )
op.create_table( op.create_table(
"user_roles", "user_roles",
sa.Column("id", postgresql.UUID(), nullable=False), sa.Column("id", postgresql.UUID(), nullable=False),
sa.Column("user_id", postgresql.UUID(), nullable=False), sa.Column("user_id", postgresql.UUID(), nullable=False),
sa.Column("role_id", postgresql.UUID(), nullable=False), sa.Column("role_id", postgresql.UUID(), nullable=False),
sa.ForeignKeyConstraint(["role_id"], ["roles.id"], name=op.f("fk_user_roles_role_id_roles")), sa.ForeignKeyConstraint(
sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_user_roles_user_id_users")), ["role_id"], ["roles.id"], name=op.f("fk_user_roles_role_id_roles")
),
sa.ForeignKeyConstraint(
["user_id"], ["users.id"], name=op.f("fk_user_roles_user_id_users")
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_user_roles")), sa.PrimaryKeyConstraint("id", name=op.f("pk_user_roles")),
sa.UniqueConstraint("user_id", "role_id", name=op.f("uq_user_roles_user_id")), sa.UniqueConstraint("user_id", "role_id", name=op.f("uq_user_roles_user_id")),
) )
@ -240,10 +275,14 @@ def upgrade():
sa.Column("is_active", sa.Boolean(), nullable=False), sa.Column("is_active", sa.Boolean(), nullable=False),
sa.Column("sort_order", sa.Numeric(), nullable=False), sa.Column("sort_order", sa.Numeric(), nullable=False),
sa.ForeignKeyConstraint( sa.ForeignKeyConstraint(
["menu_category_id"], ["menu_categories.id"], name=op.f("fk_products_menu_category_id_menu_categories") ["menu_category_id"],
["menu_categories.id"],
name=op.f("fk_products_menu_category_id_menu_categories"),
), ),
sa.ForeignKeyConstraint( sa.ForeignKeyConstraint(
["sale_category_id"], ["sale_categories.id"], name=op.f("fk_products_sale_category_id_sale_categories") ["sale_category_id"],
["sale_categories.id"],
name=op.f("fk_products_sale_category_id_sale_categories"),
), ),
sa.PrimaryKeyConstraint("id", name=op.f("pk_products")), sa.PrimaryKeyConstraint("id", name=op.f("pk_products")),
sa.UniqueConstraint("name", "units", name=op.f("uq_products_name")), sa.UniqueConstraint("name", "units", name=op.f("uq_products_name")),
@ -263,13 +302,23 @@ def upgrade():
sa.Column("reason", sa.Unicode(length=255), nullable=True), sa.Column("reason", sa.Unicode(length=255), nullable=True),
sa.Column("voucher_type", sa.Integer(), nullable=False), sa.Column("voucher_type", sa.Integer(), nullable=False),
sa.Column("user_id", postgresql.UUID(), nullable=False), sa.Column("user_id", postgresql.UUID(), nullable=False),
sa.ForeignKeyConstraint(["customer_id"], ["customers.id"], name=op.f("fk_vouchers_customer_id_customers")),
sa.ForeignKeyConstraint( sa.ForeignKeyConstraint(
["food_table_id"], ["food_tables.id"], name=op.f("fk_vouchers_food_table_id_food_tables") ["customer_id"],
["customers.id"],
name=op.f("fk_vouchers_customer_id_customers"),
),
sa.ForeignKeyConstraint(
["food_table_id"],
["food_tables.id"],
name=op.f("fk_vouchers_food_table_id_food_tables"),
),
sa.ForeignKeyConstraint(
["user_id"], ["users.id"], name=op.f("fk_vouchers_user_id_users")
), ),
sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_vouchers_user_id_users")),
sa.PrimaryKeyConstraint("id", name=op.f("pk_vouchers")), sa.PrimaryKeyConstraint("id", name=op.f("pk_vouchers")),
sa.UniqueConstraint("bill_id", "voucher_type", name=op.f("uq_vouchers_bill_id")), sa.UniqueConstraint(
"bill_id", "voucher_type", name=op.f("uq_vouchers_bill_id")
),
sa.UniqueConstraint("kot_id", name=op.f("uq_vouchers_kot_id")), sa.UniqueConstraint("kot_id", name=op.f("uq_vouchers_kot_id")),
) )
op.create_index(op.f("ix_vouchers_date"), "vouchers", ["date"], unique=False) op.create_index(op.f("ix_vouchers_date"), "vouchers", ["date"], unique=False)
@ -281,9 +330,17 @@ def upgrade():
sa.Column("food_table_id", postgresql.UUID(), nullable=False), sa.Column("food_table_id", postgresql.UUID(), nullable=False),
sa.Column("date", sa.DateTime(), nullable=False), sa.Column("date", sa.DateTime(), nullable=False),
sa.Column("user_id", postgresql.UUID(), nullable=False), sa.Column("user_id", postgresql.UUID(), nullable=False),
sa.ForeignKeyConstraint(["food_table_id"], ["food_tables.id"], name=op.f("fk_kots_food_table_id_food_tables")), sa.ForeignKeyConstraint(
sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_kots_user_id_users")), ["food_table_id"],
sa.ForeignKeyConstraint(["voucher_id"], ["vouchers.id"], name=op.f("fk_kots_voucher_id_vouchers")), ["food_tables.id"],
name=op.f("fk_kots_food_table_id_food_tables"),
),
sa.ForeignKeyConstraint(
["user_id"], ["users.id"], name=op.f("fk_kots_user_id_users")
),
sa.ForeignKeyConstraint(
["voucher_id"], ["vouchers.id"], name=op.f("fk_kots_voucher_id_vouchers")
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_kots")), sa.PrimaryKeyConstraint("id", name=op.f("pk_kots")),
sa.UniqueConstraint("code", name=op.f("uq_kots_code")), sa.UniqueConstraint("code", name=op.f("uq_kots_code")),
) )
@ -297,14 +354,20 @@ def upgrade():
sa.ForeignKeyConstraint( sa.ForeignKeyConstraint(
["modifier_categories_id"], ["modifier_categories_id"],
["modifier_categories.id"], ["modifier_categories.id"],
name=op.f("fk_modifier_categories_products_modifier_categories_id_modifier_categories"), name=op.f(
"fk_modifier_categories_products_modifier_categories_id_modifier_categories"
),
), ),
sa.ForeignKeyConstraint( sa.ForeignKeyConstraint(
["product_id"], ["products.id"], name=op.f("fk_modifier_categories_products_product_id_products") ["product_id"],
["products.id"],
name=op.f("fk_modifier_categories_products_product_id_products"),
), ),
sa.PrimaryKeyConstraint("id", name=op.f("pk_modifier_categories_products")), sa.PrimaryKeyConstraint("id", name=op.f("pk_modifier_categories_products")),
sa.UniqueConstraint( sa.UniqueConstraint(
"product_id", "modifier_categories_id", name=op.f("uq_modifier_categories_products_product_id") "product_id",
"modifier_categories_id",
name=op.f("uq_modifier_categories_products_product_id"),
), ),
) )
op.create_table( op.create_table(
@ -315,12 +378,20 @@ def upgrade():
sa.Column("guest_book_id", postgresql.UUID(), nullable=True), sa.Column("guest_book_id", postgresql.UUID(), nullable=True),
sa.Column("status", sa.Unicode(length=255), nullable=False), sa.Column("status", sa.Unicode(length=255), nullable=False),
sa.ForeignKeyConstraint( sa.ForeignKeyConstraint(
["food_table_id"], ["food_tables.id"], name=op.f("fk_overview_food_table_id_food_tables") ["food_table_id"],
["food_tables.id"],
name=op.f("fk_overview_food_table_id_food_tables"),
), ),
sa.ForeignKeyConstraint( sa.ForeignKeyConstraint(
["guest_book_id"], ["guest_book.id"], name=op.f("fk_overview_guest_book_id_guest_book") ["guest_book_id"],
["guest_book.id"],
name=op.f("fk_overview_guest_book_id_guest_book"),
),
sa.ForeignKeyConstraint(
["voucher_id"],
["vouchers.id"],
name=op.f("fk_overview_voucher_id_vouchers"),
), ),
sa.ForeignKeyConstraint(["voucher_id"], ["vouchers.id"], name=op.f("fk_overview_voucher_id_vouchers")),
sa.PrimaryKeyConstraint("id", name=op.f("pk_overview")), sa.PrimaryKeyConstraint("id", name=op.f("pk_overview")),
sa.UniqueConstraint("food_table_id", name=op.f("uq_overview_food_table_id")), sa.UniqueConstraint("food_table_id", name=op.f("uq_overview_food_table_id")),
sa.UniqueConstraint("guest_book_id", name=op.f("uq_overview_guest_book_id")), sa.UniqueConstraint("guest_book_id", name=op.f("uq_overview_guest_book_id")),
@ -332,24 +403,44 @@ def upgrade():
sa.Column("date", sa.DateTime(), nullable=False), sa.Column("date", sa.DateTime(), nullable=False),
sa.Column("voucher_id", postgresql.UUID(), nullable=False), sa.Column("voucher_id", postgresql.UUID(), nullable=False),
sa.Column("user_id", postgresql.UUID(), nullable=False), sa.Column("user_id", postgresql.UUID(), nullable=False),
sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_reprints_user_id_users")), sa.ForeignKeyConstraint(
sa.ForeignKeyConstraint(["voucher_id"], ["vouchers.id"], name=op.f("fk_reprints_voucher_id_vouchers")), ["user_id"], ["users.id"], name=op.f("fk_reprints_user_id_users")
),
sa.ForeignKeyConstraint(
["voucher_id"],
["vouchers.id"],
name=op.f("fk_reprints_voucher_id_vouchers"),
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_reprints")), sa.PrimaryKeyConstraint("id", name=op.f("pk_reprints")),
) )
op.create_index(op.f("ix_reprints_date"), "reprints", ["date"], unique=False) op.create_index(op.f("ix_reprints_date"), "reprints", ["date"], unique=False)
op.create_index(op.f("ix_reprints_voucher_id"), "reprints", ["voucher_id"], unique=False) op.create_index(
op.f("ix_reprints_voucher_id"), "reprints", ["voucher_id"], unique=False
)
op.create_table( op.create_table(
"settlements", "settlements",
sa.Column("id", postgresql.UUID(), nullable=False), sa.Column("id", postgresql.UUID(), nullable=False),
sa.Column("voucher_id", postgresql.UUID(), nullable=False), sa.Column("voucher_id", postgresql.UUID(), nullable=False),
sa.Column("settled", sa.Integer(), nullable=False), sa.Column("settled", sa.Integer(), nullable=False),
sa.Column("amount", sa.Numeric(), nullable=False), sa.Column("amount", sa.Numeric(), nullable=False),
sa.ForeignKeyConstraint(["settled"], ["settle_options.id"], name=op.f("fk_settlements_settled_settle_options")), sa.ForeignKeyConstraint(
sa.ForeignKeyConstraint(["voucher_id"], ["vouchers.id"], name=op.f("fk_settlements_voucher_id_vouchers")), ["settled"],
["settle_options.id"],
name=op.f("fk_settlements_settled_settle_options"),
),
sa.ForeignKeyConstraint(
["voucher_id"],
["vouchers.id"],
name=op.f("fk_settlements_voucher_id_vouchers"),
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_settlements")), sa.PrimaryKeyConstraint("id", name=op.f("pk_settlements")),
sa.UniqueConstraint("voucher_id", "settled", name=op.f("uq_settlements_voucher_id")), sa.UniqueConstraint(
"voucher_id", "settled", name=op.f("uq_settlements_voucher_id")
),
)
op.create_index(
op.f("ix_settlements_voucher_id"), "settlements", ["voucher_id"], unique=False
) )
op.create_index(op.f("ix_settlements_voucher_id"), "settlements", ["voucher_id"], unique=False)
op.create_table( op.create_table(
"inventories", "inventories",
sa.Column("id", postgresql.UUID(), nullable=False), sa.Column("id", postgresql.UUID(), nullable=False),
@ -362,13 +453,29 @@ def upgrade():
sa.Column("tax_id", postgresql.UUID(), nullable=False), sa.Column("tax_id", postgresql.UUID(), nullable=False),
sa.Column("discount", sa.Numeric(), nullable=True), sa.Column("discount", sa.Numeric(), nullable=True),
sa.Column("sort_order", sa.Numeric(), nullable=False), sa.Column("sort_order", sa.Numeric(), nullable=False),
sa.ForeignKeyConstraint(["kot_id"], ["kots.id"], name=op.f("fk_inventories_kot_id_kots")), sa.ForeignKeyConstraint(
sa.ForeignKeyConstraint(["product_id"], ["products.id"], name=op.f("fk_inventories_product_id_products")), ["kot_id"], ["kots.id"], name=op.f("fk_inventories_kot_id_kots")
sa.ForeignKeyConstraint(["tax_id"], ["taxes.id"], name=op.f("fk_inventories_tax_id_taxes")), ),
sa.ForeignKeyConstraint(
["product_id"],
["products.id"],
name=op.f("fk_inventories_product_id_products"),
),
sa.ForeignKeyConstraint(
["tax_id"], ["taxes.id"], name=op.f("fk_inventories_tax_id_taxes")
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_inventories")), sa.PrimaryKeyConstraint("id", name=op.f("pk_inventories")),
sa.UniqueConstraint("kot_id", "product_id", "is_happy_hour", "price", name=op.f("uq_inventories_kot_id")), sa.UniqueConstraint(
"kot_id",
"product_id",
"is_happy_hour",
"price",
name=op.f("uq_inventories_kot_id"),
),
)
op.create_index(
op.f("ix_inventories_kot_id"), "inventories", ["kot_id"], unique=False
) )
op.create_index(op.f("ix_inventories_kot_id"), "inventories", ["kot_id"], unique=False)
op.create_table( op.create_table(
"inventory_modifiers", "inventory_modifiers",
sa.Column("id", postgresql.UUID(), nullable=False), sa.Column("id", postgresql.UUID(), nullable=False),
@ -376,20 +483,48 @@ def upgrade():
sa.Column("modifier_id", postgresql.UUID(), nullable=False), sa.Column("modifier_id", postgresql.UUID(), nullable=False),
sa.Column("price", sa.Numeric(), nullable=False), sa.Column("price", sa.Numeric(), nullable=False),
sa.ForeignKeyConstraint( sa.ForeignKeyConstraint(
["inventory_id"], ["inventories.id"], name=op.f("fk_inventory_modifiers_inventory_id_inventories") ["inventory_id"],
["inventories.id"],
name=op.f("fk_inventory_modifiers_inventory_id_inventories"),
), ),
sa.ForeignKeyConstraint( sa.ForeignKeyConstraint(
["modifier_id"], ["modifiers.id"], name=op.f("fk_inventory_modifiers_modifier_id_modifiers") ["modifier_id"],
["modifiers.id"],
name=op.f("fk_inventory_modifiers_modifier_id_modifiers"),
), ),
sa.PrimaryKeyConstraint("id", name=op.f("pk_inventory_modifiers")), sa.PrimaryKeyConstraint("id", name=op.f("pk_inventory_modifiers")),
sa.UniqueConstraint("inventory_id", "modifier_id", name=op.f("uq_inventory_modifiers_inventory_id")), sa.UniqueConstraint(
"inventory_id",
"modifier_id",
name=op.f("uq_inventory_modifiers_inventory_id"),
),
) )
op.execute(Permission.__table__.insert().values(id="7669dfc9-cc75-4e48-b267-145c8832a83c", name="Guest Book")) op.execute(
op.execute(Permission.__table__.insert().values(id="5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c", name="Printers")) Permission.__table__.insert().values(
op.execute(Permission.__table__.insert().values(id="c973f32c-a37b-496a-8dc5-60d2e4c39e97", name="Sections")) id="7669dfc9-cc75-4e48-b267-145c8832a83c", name="Guest Book"
op.execute(Permission.__table__.insert().values(id="7a04ba63-5d08-4078-9051-a6d91cce3e48", name="Section Printers")) )
op.execute(Section.__table__.insert().values(id="3f13f6e7-dc76-4fca-8fdb-b2bbf29b35df", name="Main")) )
op.execute(
Permission.__table__.insert().values(
id="5b66c6f6-003a-4ef8-ba28-49b8ff1ac33c", name="Printers"
)
)
op.execute(
Permission.__table__.insert().values(
id="c973f32c-a37b-496a-8dc5-60d2e4c39e97", name="Sections"
)
)
op.execute(
Permission.__table__.insert().values(
id="7a04ba63-5d08-4078-9051-a6d91cce3e48", name="Section Printers"
)
)
op.execute(
Section.__table__.insert().values(
id="3f13f6e7-dc76-4fca-8fdb-b2bbf29b35df", name="Main"
)
)
op.execute( op.execute(
ModifierCategory.__table__.insert().values( ModifierCategory.__table__.insert().values(
@ -454,15 +589,25 @@ def upgrade():
op.execute( op.execute(
SettleOption.__table__.insert().values( SettleOption.__table__.insert().values(
id=1, name="Unsettled", show_in_choices=False, display_group=1, is_print=True id=1,
name="Unsettled",
show_in_choices=False,
display_group=1,
is_print=True,
) )
) )
op.execute( op.execute(
SettleOption.__table__.insert().values(id=2, name="Cash", show_in_choices=True, display_group=2, is_print=False) SettleOption.__table__.insert().values(
id=2, name="Cash", show_in_choices=True, display_group=2, is_print=False
)
) )
op.execute( op.execute(
SettleOption.__table__.insert().values( SettleOption.__table__.insert().values(
id=3, name="Credit Card", show_in_choices=True, display_group=2, is_print=True id=3,
name="Credit Card",
show_in_choices=True,
display_group=2,
is_print=True,
) )
) )
op.execute( op.execute(
@ -472,15 +617,25 @@ def upgrade():
) )
op.execute( op.execute(
SettleOption.__table__.insert().values( SettleOption.__table__.insert().values(
id=5, name="Bill To Company", show_in_choices=True, display_group=2, is_print=True id=5,
name="Bill To Company",
show_in_choices=True,
display_group=2,
is_print=True,
) )
) )
op.execute( op.execute(
SettleOption.__table__.insert().values(id=6, name="Tip", show_in_choices=True, display_group=2, is_print=True) SettleOption.__table__.insert().values(
id=6, name="Tip", show_in_choices=True, display_group=2, is_print=True
)
) )
op.execute( op.execute(
SettleOption.__table__.insert().values( SettleOption.__table__.insert().values(
id=7, name="Round Off", show_in_choices=False, display_group=1, is_print=False id=7,
name="Round Off",
show_in_choices=False,
display_group=1,
is_print=False,
) )
) )
op.execute( op.execute(
@ -489,7 +644,9 @@ def upgrade():
) )
) )
op.execute( op.execute(
SettleOption.__table__.insert().values(id=9, name="Void", show_in_choices=True, display_group=1, is_print=True) SettleOption.__table__.insert().values(
id=9, name="Void", show_in_choices=True, display_group=1, is_print=True
)
) )
op.execute( op.execute(
SettleOption.__table__.insert().values( SettleOption.__table__.insert().values(
@ -498,7 +655,11 @@ def upgrade():
) )
op.execute( op.execute(
Customer.__table__.insert().values( Customer.__table__.insert().values(
id="2c716f4b-0736-429a-ad51-610d7c47cb5e", company="", name="Cash", phone="", address="" id="2c716f4b-0736-429a-ad51-610d7c47cb5e",
company="",
name="Cash",
phone="",
address="",
) )
) )
op.execute( op.execute(

View File

@ -0,0 +1,19 @@
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def init() -> None:
pass
def main() -> None:
logger.info("Initializing service")
init()
logger.info("Service finished initializing")
if __name__ == "__main__":
main()

View File

@ -0,0 +1,7 @@
from barker.core.config import settings
from celery import Celery
celery_app = Celery("tasks", broker=settings.RABBITMQ_URI)
celery_app.conf.task_routes = {"barker.worker.sent_to_printer": "main-queue"}

View File

@ -18,23 +18,8 @@ class Settings(BaseSettings):
PORT: int = 80 PORT: int = 80
DEBUG: bool = False DEBUG: bool = False
LOG_LEVEL: str = "NOTSET" LOG_LEVEL: str = "NOTSET"
POSTGRES_SERVER: str = "" SQLALCHEMY_DATABASE_URI: str = None
POSTGRES_USER: str = "postgres" RABBITMQ_URI: str = None
POSTGRES_PASSWORD: str = ""
POSTGRES_DB: str = ""
SQLALCHEMY_DATABASE_URI: Optional[str] = None
@validator("SQLALCHEMY_DATABASE_URI", pre=True)
def assemble_db_connection(cls, v: Optional[str], values: Dict[str, Any]) -> Any:
if isinstance(v, str):
return v
return PostgresDsn.build(
scheme="postgresql",
user=values.get("POSTGRES_USER"),
password=values.get("POSTGRES_PASSWORD"),
host=values.get("POSTGRES_SERVER"),
path=f"/{values.get('POSTGRES_DB') or ''}",
)
ALEMBIC_LOG_LEVEL: str = "INFO" ALEMBIC_LOG_LEVEL: str = "INFO"
ALEMBIC_SQLALCHEMY_LOG_LEVEL: str = "WARN" ALEMBIC_SQLALCHEMY_LOG_LEVEL: str = "WARN"

View File

@ -4,8 +4,8 @@ from decimal import Decimal
from typing import Optional from typing import Optional
import barker.schemas.voucher as schemas import barker.schemas.voucher as schemas
from barker.models import VoucherType
from barker.models import VoucherType
from fastapi import APIRouter, Depends, HTTPException, Security, status from fastapi import APIRouter, Depends, HTTPException, Security, status
from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.orm import Session from sqlalchemy.orm import Session

View File

@ -131,7 +131,7 @@ def do_save(
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, status_code=status.HTTP_403_FORBIDDEN,
detail=f"You are not allowed to delete printed products." detail=f"You are not allowed to delete printed products."
f"\n In this case {product.full_name}", f"\n In this case {product.full_name}",
) )
tax_rate = get_tax(product.sale_category.tax.rate, voucher_type) tax_rate = get_tax(product.sale_category.tax.rate, voucher_type)
inv = Inventory( inv = Inventory(

View File

@ -2,12 +2,11 @@ import re
import socket import socket
import sys import sys
from celery import Celery from barker.core.celery_app import celery_app
from celery.utils.log import get_task_logger from celery.utils.log import get_task_logger
# Create the celery app and get the logger # Create the celery app and get the logger
celery_app = Celery("tasks", broker="pyamqp://guest@localhost//")
logger = get_task_logger(__name__) logger = get_task_logger(__name__)

6
barker/worker-start.sh Normal file
View File

@ -0,0 +1,6 @@
#! /usr/bin/env bash
set -e
python /app/barker/celeryworker_pre_start.py
celery worker --app barker.worker --loglevel info --queues main-queue --concurrency 1