Moved brewman python project down a level into its own folder

This commit is contained in:
2020-10-10 11:19:15 +05:30
parent 00321fe022
commit 889cac237c
90 changed files with 23 additions and 8 deletions

3
brewman/.flake8 Normal file
View File

@ -0,0 +1,3 @@
[flake8]
max-line-length = 120
exclude = .git,__pycache__,__init__.py,.mypy_cache,.pytest_cache

3
brewman/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.pyc
*/__pycache__/
*.egg-info/

3
brewman/alembic.ini Normal file
View File

@ -0,0 +1,3 @@
[alembic]
# path to migration scripts
script_location = alembic

1
brewman/alembic/README Normal file
View File

@ -0,0 +1 @@
Generic single-database configuration.

70
brewman/alembic/env.py Normal file
View File

@ -0,0 +1,70 @@
import logging
from sqlalchemy import create_engine
from sqlalchemy import pool
from alembic import context
from brewman.core.config import settings
logging.basicConfig()
logging.getLogger("sqlalchemy.engine").setLevel(settings.ALEMBIC_LOG_LEVEL)
logging.getLogger("alembic").setLevel(settings.ALEMBIC_LOG_LEVEL)
# Interpret the config file for Python logging.
# This line sets up loggers basically.
from brewman.models.auth import User # noqa
target_metadata = User.metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = settings.SQLALCHEMY_DATABASE_URI
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
compare_type=True,
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = create_engine(settings.SQLALCHEMY_DATABASE_URI, poolclass=pool.NullPool,)
with connectable.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata, compare_type=True)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

View File

@ -0,0 +1,364 @@
"""Initial Commit
Revision ID: 0bf3d70ee7de
Revises:
Create Date: 2020-05-10 19:02:57.301086
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = "0bf3d70ee7de"
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"auth_clients",
sa.Column("client_id", postgresql.UUID(), nullable=False),
sa.Column("code", sa.Integer(), nullable=False),
sa.Column("name", sa.Unicode(length=255), nullable=False),
sa.Column("enabled", sa.Boolean(), nullable=False),
sa.Column("otp", sa.Integer(), nullable=True),
sa.Column("creation_date", sa.DateTime(timezone=True), nullable=False),
sa.PrimaryKeyConstraint("client_id", name=op.f("pk_auth_clients")),
sa.UniqueConstraint("code", name=op.f("uq_auth_clients_code")),
sa.UniqueConstraint("name", name=op.f("uq_auth_clients_name")),
)
op.create_table(
"auth_groups",
sa.Column("GroupID", postgresql.UUID(), nullable=False),
sa.Column("Name", sa.Unicode(length=255), nullable=True),
sa.PrimaryKeyConstraint("GroupID", name=op.f("pk_auth_groups")),
sa.UniqueConstraint("Name", name=op.f("uq_auth_groups_Name")),
)
op.create_table(
"auth_roles",
sa.Column("RoleID", postgresql.UUID(), nullable=False),
sa.Column("Name", sa.Unicode(length=255), nullable=True),
sa.PrimaryKeyConstraint("RoleID", name=op.f("pk_auth_roles")),
sa.UniqueConstraint("Name", name=op.f("uq_auth_roles_Name")),
)
op.create_table(
"auth_users",
sa.Column("UserID", postgresql.UUID(), nullable=False),
sa.Column("Name", sa.Unicode(length=255), nullable=True),
sa.Column("Password", sa.Unicode(length=60), nullable=True),
sa.Column("LockedOut", sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint("UserID", name=op.f("pk_auth_users")),
sa.UniqueConstraint("Name", name=op.f("uq_auth_users_Name")),
)
op.create_table(
"cost_centres",
sa.Column("CostCentreID", postgresql.UUID(), nullable=False),
sa.Column("Name", sa.Unicode(length=255), nullable=True),
sa.Column("IsFixture", sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint("CostCentreID", name=op.f("pk_cost_centres")),
sa.UniqueConstraint("Name", name=op.f("uq_cost_centres_Name")),
)
op.create_table(
"images",
sa.Column("id", postgresql.UUID(), nullable=False),
sa.Column("resource_id", postgresql.UUID(), nullable=False),
sa.Column("resource_type", sa.Unicode(length=255), nullable=False),
sa.Column("image", postgresql.BYTEA(), nullable=False),
sa.Column("thumbnail", postgresql.BYTEA(), nullable=False),
sa.Column("creation_date", sa.DateTime(timezone=True), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("pk_images")),
)
op.create_table(
"product_groups",
sa.Column("ProductGroupID", postgresql.UUID(), nullable=False),
sa.Column("Name", sa.Unicode(length=255), nullable=True),
sa.Column("IsFixture", sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint("ProductGroupID", name=op.f("pk_product_groups")),
sa.UniqueConstraint("Name", name=op.f("uq_product_groups_Name")),
)
op.create_table(
"settings",
sa.Column("SettingID", postgresql.UUID(), nullable=False),
sa.Column("Name", sa.Unicode(length=255), nullable=False),
sa.Column("Data", sa.PickleType(), nullable=True),
sa.PrimaryKeyConstraint("SettingID", name=op.f("pk_settings")),
sa.UniqueConstraint("Name", name=op.f("uq_settings_Name")),
)
op.create_table(
"accounts",
sa.Column("id", postgresql.UUID(), nullable=False),
sa.Column("code", sa.Integer(), nullable=False),
sa.Column("name", sa.Unicode(length=255), nullable=False),
sa.Column("type", sa.Integer(), nullable=False),
sa.Column("account_type", sa.Unicode(length=50), nullable=False),
sa.Column("is_starred", sa.Boolean(), nullable=False),
sa.Column("is_active", sa.Boolean(), nullable=False),
sa.Column("is_reconcilable", sa.Boolean(), nullable=False),
sa.Column("cost_centre_id", postgresql.UUID(), nullable=False),
sa.Column("is_fixture", sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(
["cost_centre_id"], ["cost_centres.CostCentreID"], name=op.f("fk_accounts_cost_centre_id_cost_centres"),
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_accounts")),
sa.UniqueConstraint("name", name=op.f("uq_accounts_name")),
)
op.create_table(
"auth_login_history",
sa.Column("login_history_id", postgresql.UUID(), nullable=False),
sa.Column("user_id", postgresql.UUID(), nullable=False),
sa.Column("client_id", postgresql.UUID(), nullable=False),
sa.Column("date", sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(
["client_id"], ["auth_clients.client_id"], name=op.f("fk_auth_login_history_client_id_auth_clients"),
),
sa.ForeignKeyConstraint(
["user_id"], ["auth_users.UserID"], name=op.f("fk_auth_login_history_user_id_auth_users"),
),
sa.PrimaryKeyConstraint("login_history_id", name=op.f("pk_auth_login_history")),
sa.UniqueConstraint("user_id", "client_id", "date", name=op.f("uq_auth_login_history_user_id")),
)
op.create_table(
"auth_rolegroups",
sa.Column("RoleGroupID", postgresql.UUID(), nullable=False),
sa.Column("RoleID", postgresql.UUID(), nullable=True),
sa.Column("GroupID", postgresql.UUID(), nullable=True),
sa.ForeignKeyConstraint(
["GroupID"], ["auth_groups.GroupID"], name=op.f("fk_auth_rolegroups_GroupID_auth_groups"),
),
sa.ForeignKeyConstraint(["RoleID"], ["auth_roles.RoleID"], name=op.f("fk_auth_rolegroups_RoleID_auth_roles"),),
sa.PrimaryKeyConstraint("RoleGroupID", name=op.f("pk_auth_rolegroups")),
)
op.create_table(
"auth_usergroups",
sa.Column("UserGroupID", postgresql.UUID(), nullable=False),
sa.Column("UserID", postgresql.UUID(), nullable=True),
sa.Column("GroupID", postgresql.UUID(), nullable=True),
sa.ForeignKeyConstraint(
["GroupID"], ["auth_groups.GroupID"], name=op.f("fk_auth_usergroups_GroupID_auth_groups"),
),
sa.ForeignKeyConstraint(["UserID"], ["auth_users.UserID"], name=op.f("fk_auth_usergroups_UserID_auth_users"),),
sa.PrimaryKeyConstraint("UserGroupID", name=op.f("pk_auth_usergroups")),
)
op.create_table(
"vouchers",
sa.Column("VoucherID", postgresql.UUID(), nullable=False),
sa.Column("date", sa.DateTime(), nullable=False),
sa.Column("narration", sa.Unicode(length=1000), nullable=False),
sa.Column("is_reconciled", sa.Boolean(), nullable=False),
sa.Column("reconcile_date", sa.DateTime(), nullable=False),
sa.Column("is_starred", sa.Boolean(), nullable=False),
sa.Column("creation_date", sa.DateTime(timezone=True), nullable=False),
sa.Column("last_edit_date", sa.DateTime(timezone=True), nullable=False),
sa.Column("voucher_type", sa.Integer(), nullable=False),
sa.Column("user_id", postgresql.UUID(), nullable=False),
sa.Column("is_posted", sa.Boolean(), nullable=False),
sa.Column("poster_id", postgresql.UUID(), nullable=True),
sa.ForeignKeyConstraint(["poster_id"], ["auth_users.UserID"], name=op.f("fk_vouchers_poster_id_auth_users"),),
sa.ForeignKeyConstraint(["user_id"], ["auth_users.UserID"], name=op.f("fk_vouchers_user_id_auth_users"),),
sa.PrimaryKeyConstraint("VoucherID", name=op.f("pk_vouchers")),
)
op.create_index(op.f("ix_vouchers_date"), "vouchers", ["date"], unique=False)
op.create_table(
"employees",
sa.Column("id", postgresql.UUID(), nullable=False),
sa.Column("Designation", sa.Unicode(length=255), nullable=True),
sa.Column("Salary", sa.Integer(), nullable=True),
sa.Column("ServicePoints", sa.Numeric(precision=5, scale=2), nullable=True),
sa.Column("JoiningDate", sa.DateTime(), nullable=True),
sa.Column("LeavingDate", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(["id"], ["accounts.id"], name=op.f("fk_employees_id_accounts")),
sa.PrimaryKeyConstraint("id", name=op.f("pk_employees")),
)
op.create_table(
"journals",
sa.Column("JournalID", postgresql.UUID(), nullable=False),
sa.Column("Debit", sa.Integer(), nullable=True),
sa.Column("Amount", sa.Numeric(), nullable=True),
sa.Column("VoucherID", postgresql.UUID(), nullable=False),
sa.Column("account_id", postgresql.UUID(), nullable=False),
sa.Column("CostCentreID", postgresql.UUID(), nullable=False),
sa.ForeignKeyConstraint(
["CostCentreID"], ["cost_centres.CostCentreID"], name=op.f("fk_journals_CostCentreID_cost_centres"),
),
sa.ForeignKeyConstraint(["VoucherID"], ["vouchers.VoucherID"], name=op.f("fk_journals_VoucherID_vouchers"),),
sa.ForeignKeyConstraint(["account_id"], ["accounts.id"], name=op.f("fk_journals_account_id_accounts"),),
sa.PrimaryKeyConstraint("JournalID", name=op.f("pk_journals")),
)
op.create_index(op.f("ix_journals_VoucherID"), "journals", ["VoucherID"], unique=False)
op.create_table(
"products",
sa.Column("ProductID", postgresql.UUID(), nullable=False),
sa.Column("Code", sa.Integer(), nullable=True),
sa.Column("Name", sa.Unicode(length=255), nullable=False),
sa.Column("Units", sa.Unicode(length=255), nullable=False),
sa.Column("Fraction", sa.Numeric(), nullable=False),
sa.Column("FractionUnits", sa.Unicode(length=255), nullable=False),
sa.Column("ProductYield", sa.Numeric(), nullable=False),
sa.Column("ProductGroupID", postgresql.UUID(), nullable=False),
sa.Column("account_id", postgresql.UUID(), nullable=False),
sa.Column("cost_price", sa.Numeric(), nullable=False),
sa.Column("sale_price", sa.Numeric(), nullable=False),
sa.Column("IsActive", sa.Boolean(), nullable=False),
sa.Column("IsFixture", sa.Boolean(), nullable=False),
sa.Column("is_purchased", sa.Boolean(), nullable=False),
sa.Column("is_sold", sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(
["ProductGroupID"],
["product_groups.ProductGroupID"],
name=op.f("fk_products_ProductGroupID_product_groups"),
),
sa.ForeignKeyConstraint(["account_id"], ["accounts.id"], name=op.f("fk_products_account_id_accounts"),),
sa.PrimaryKeyConstraint("ProductID", name=op.f("pk_products")),
sa.UniqueConstraint("Code", name=op.f("uq_products_Code")),
sa.UniqueConstraint("Name", "Units", name=op.f("uq_products_Name")),
)
op.create_table(
"attendances",
sa.Column("AttendanceID", postgresql.UUID(), nullable=False),
sa.Column("EmployeeID", postgresql.UUID(), nullable=True),
sa.Column("Date", sa.DateTime(), nullable=True),
sa.Column("AttendanceType", sa.Integer(), nullable=True),
sa.Column("Amount", sa.Numeric(), nullable=True),
sa.Column("CreationDate", sa.DateTime(timezone=True), nullable=True),
sa.Column("UserID", postgresql.UUID(), nullable=True),
sa.Column("IsValid", sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(["EmployeeID"], ["employees.id"], name=op.f("fk_attendances_EmployeeID_employees"),),
sa.ForeignKeyConstraint(["UserID"], ["auth_users.UserID"], name=op.f("fk_attendances_UserID_auth_users"),),
sa.PrimaryKeyConstraint("AttendanceID", name=op.f("pk_attendances")),
)
op.create_table(
"batches",
sa.Column("BatchID", postgresql.UUID(), nullable=False),
sa.Column("Name", sa.DateTime(), nullable=True),
sa.Column("ProductID", postgresql.UUID(), nullable=False),
sa.Column("QuantityRemaining", sa.Numeric(), nullable=True),
sa.Column("Rate", sa.Numeric(), nullable=True),
sa.Column("Tax", sa.Numeric(), nullable=True),
sa.Column("Discount", sa.Numeric(), nullable=True),
sa.ForeignKeyConstraint(["ProductID"], ["products.ProductID"], name=op.f("fk_batches_ProductID_products"),),
sa.PrimaryKeyConstraint("BatchID", name=op.f("pk_batches")),
)
op.create_table(
"fingerprints",
sa.Column("FingerprintID", postgresql.UUID(), nullable=False),
sa.Column("EmployeeID", postgresql.UUID(), nullable=True),
sa.Column("Date", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(["EmployeeID"], ["employees.id"], name=op.f("fk_fingerprints_EmployeeID_employees"),),
sa.PrimaryKeyConstraint("FingerprintID", name=op.f("pk_fingerprints")),
)
op.create_table(
"recipes",
sa.Column("recipe_id", postgresql.UUID(), nullable=False),
sa.Column("product_id", postgresql.UUID(), nullable=False),
sa.Column("quantity", sa.Numeric(), nullable=False),
sa.Column("cost_price", sa.Numeric(), nullable=False),
sa.Column("sale_price", sa.Numeric(), nullable=False),
sa.Column("notes", sa.Unicode(length=255), nullable=True),
sa.Column("valid_from", sa.Date(), nullable=False),
sa.Column("valid_to", sa.Date(), nullable=False),
sa.Column("effective_from", sa.Date(), nullable=False),
sa.Column("effective_to", sa.Date(), nullable=True),
sa.ForeignKeyConstraint(["product_id"], ["products.ProductID"], name=op.f("fk_recipes_product_id_products"),),
sa.PrimaryKeyConstraint("recipe_id", name=op.f("pk_recipes")),
)
op.create_table(
"salary_deductions",
sa.Column("SalaryDeductionID", postgresql.UUID(), nullable=False),
sa.Column("VoucherID", postgresql.UUID(), nullable=False),
sa.Column("JournalID", postgresql.UUID(), nullable=False),
sa.Column("GrossSalary", sa.Integer(), nullable=True),
sa.Column("DaysWorked", sa.Integer(), nullable=True),
sa.Column("EsiEmployee", sa.Integer(), nullable=True),
sa.Column("PfEmployee", sa.Integer(), nullable=True),
sa.Column("EsiEmployer", sa.Integer(), nullable=True),
sa.Column("PfEmployer", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
["JournalID"], ["journals.JournalID"], name=op.f("fk_salary_deductions_JournalID_journals"),
),
sa.ForeignKeyConstraint(
["VoucherID"], ["vouchers.VoucherID"], name=op.f("fk_salary_deductions_VoucherID_vouchers"),
),
sa.PrimaryKeyConstraint("SalaryDeductionID", name=op.f("pk_salary_deductions")),
)
op.create_table(
"service_charges",
sa.Column("id", postgresql.UUID(), nullable=False),
sa.Column("voucher_id", postgresql.UUID(), nullable=False),
sa.Column("journal_id", postgresql.UUID(), nullable=False),
sa.Column("days_worked", sa.Integer(), nullable=False),
sa.Column("points", sa.Numeric(precision=5, scale=2), nullable=False),
sa.ForeignKeyConstraint(
["journal_id"], ["journals.JournalID"], name=op.f("fk_service_charges_journal_id_journals"),
),
sa.ForeignKeyConstraint(
["voucher_id"], ["vouchers.VoucherID"], name=op.f("fk_service_charges_voucher_id_vouchers"),
),
sa.PrimaryKeyConstraint("id", name=op.f("pk_service_charges")),
)
op.create_table(
"inventories",
sa.Column("InventoryID", postgresql.UUID(), nullable=False),
sa.Column("VoucherID", postgresql.UUID(), nullable=False),
sa.Column("ProductID", postgresql.UUID(), nullable=False),
sa.Column("BatchID", postgresql.UUID(), nullable=False),
sa.Column("Quantity", sa.Numeric(), nullable=True),
sa.Column("Rate", sa.Numeric(), nullable=True),
sa.Column("Tax", sa.Numeric(), nullable=True),
sa.Column("Discount", sa.Numeric(), nullable=True),
sa.ForeignKeyConstraint(["BatchID"], ["batches.BatchID"], name=op.f("fk_inventories_BatchID_batches"),),
sa.ForeignKeyConstraint(["ProductID"], ["products.ProductID"], name=op.f("fk_inventories_ProductID_products"),),
sa.ForeignKeyConstraint(["VoucherID"], ["vouchers.VoucherID"], name=op.f("fk_inventories_VoucherID_vouchers"),),
sa.PrimaryKeyConstraint("InventoryID", name=op.f("pk_inventories")),
sa.UniqueConstraint("VoucherID", "BatchID", name=op.f("uq_inventories_VoucherID")),
)
op.create_index(op.f("ix_inventories_VoucherID"), "inventories", ["VoucherID"], unique=False)
op.create_table(
"recipe_items",
sa.Column("recipe_item_id", postgresql.UUID(), nullable=False),
sa.Column("recipe_id", postgresql.UUID(), nullable=False),
sa.Column("product_id", postgresql.UUID(), nullable=False),
sa.Column("quantity", sa.Integer(), nullable=False),
sa.Column("price", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(
["product_id"], ["products.ProductID"], name=op.f("fk_recipe_items_product_id_products"),
),
sa.ForeignKeyConstraint(["recipe_id"], ["recipes.recipe_id"], name=op.f("fk_recipe_items_recipe_id_recipes"),),
sa.PrimaryKeyConstraint("recipe_item_id", name=op.f("pk_recipe_items")),
sa.UniqueConstraint("recipe_id", "product_id", name=op.f("uq_recipe_items_recipe_id")),
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("recipe_items")
op.drop_index(op.f("ix_inventories_VoucherID"), table_name="inventories")
op.drop_table("inventories")
op.drop_table("service_charges")
op.drop_table("salary_deductions")
op.drop_table("recipes")
op.drop_table("fingerprints")
op.drop_table("batches")
op.drop_table("attendances")
op.drop_table("products")
op.drop_index(op.f("ix_journals_VoucherID"), table_name="journals")
op.drop_table("journals")
op.drop_table("employees")
op.drop_index(op.f("ix_vouchers_date"), table_name="vouchers")
op.drop_table("vouchers")
op.drop_table("auth_usergroups")
op.drop_table("auth_rolegroups")
op.drop_table("auth_login_history")
op.drop_table("accounts")
op.drop_table("settings")
op.drop_table("product_groups")
op.drop_table("images")
op.drop_table("cost_centres")
op.drop_table("auth_users")
op.drop_table("auth_roles")
op.drop_table("auth_groups")
op.drop_table("auth_clients")
# ### end Alembic commands ###

View File

@ -0,0 +1,248 @@
"""lowercase and fastapi
Revision ID: eed0b382c287
Revises: 0bf3d70ee7de
Create Date: 2020-05-10 19:52:58.163810
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import table, column, select
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = "eed0b382c287"
down_revision = "0bf3d70ee7de"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("msg_subscribers")
op.drop_table("msg_posts")
op.drop_table("msg_threadtags")
op.drop_table("msg_threads")
op.drop_table("msg_tags")
op.rename_table("auth_roles", "auth_permissions")
with op.batch_alter_table("auth_permissions") as batch_op:
batch_op.alter_column("RoleID", new_column_name="id")
batch_op.alter_column("Name", new_column_name="name")
op.rename_table("auth_groups", "auth_roles")
with op.batch_alter_table("auth_roles") as batch_op:
batch_op.alter_column("GroupID", new_column_name="id")
batch_op.alter_column("Name", new_column_name="name")
op.rename_table("auth_rolegroups", "role_permissions")
with op.batch_alter_table("role_permissions") as batch_op:
batch_op.alter_column("RoleGroupID", new_column_name="id")
batch_op.alter_column("RoleID", new_column_name="permission_id")
batch_op.alter_column("GroupID", new_column_name="role_id")
op.rename_table("auth_usergroups", "user_roles")
with op.batch_alter_table("user_roles") as batch_op:
batch_op.alter_column("UserGroupID", new_column_name="id")
batch_op.alter_column("UserID", new_column_name="user_id")
batch_op.alter_column("GroupID", new_column_name="role_id")
with op.batch_alter_table("attendances") as batch_op:
batch_op.alter_column("Amount", new_column_name="amount")
batch_op.alter_column("UserID", new_column_name="user_id")
batch_op.alter_column("AttendanceType", new_column_name="attendance_type")
batch_op.alter_column("CreationDate", new_column_name="creation_date")
batch_op.alter_column("Date", new_column_name="date", type_=sa.Date(), nullable=False)
batch_op.alter_column("EmployeeID", new_column_name="employee_id")
batch_op.alter_column("AttendanceID", new_column_name="id")
batch_op.alter_column("IsValid", new_column_name="is_valid")
with op.batch_alter_table("auth_users") as batch_op:
batch_op.alter_column("UserID", new_column_name="id")
batch_op.alter_column("Name", new_column_name="username")
batch_op.alter_column("Password", new_column_name="password")
batch_op.alter_column("LockedOut", new_column_name="disabled")
with op.batch_alter_table("batches") as batch_op:
batch_op.alter_column("BatchID", new_column_name="id")
batch_op.alter_column("Discount", new_column_name="discount")
batch_op.alter_column("Name", new_column_name="name", type_=sa.Date(), nullable=False)
batch_op.alter_column("ProductID", new_column_name="product_id")
batch_op.alter_column("QuantityRemaining", new_column_name="quantity_remaining")
batch_op.alter_column("Rate", new_column_name="rate")
batch_op.alter_column("Tax", new_column_name="tax")
with op.batch_alter_table("cost_centres") as batch_op:
batch_op.alter_column("CostCentreID", new_column_name="id")
batch_op.alter_column("Name", new_column_name="name")
batch_op.alter_column("IsFixture", new_column_name="is_fixture")
with op.batch_alter_table("product_groups") as batch_op:
batch_op.alter_column("ProductGroupID", new_column_name="id")
batch_op.alter_column("Name", new_column_name="name")
batch_op.alter_column("IsFixture", new_column_name="is_fixture")
with op.batch_alter_table("inventories") as batch_op:
batch_op.alter_column("InventoryID", new_column_name="id")
batch_op.alter_column("BatchID", new_column_name="batch_id")
batch_op.alter_column("Discount", new_column_name="discount")
batch_op.alter_column("ProductID", new_column_name="product_id")
batch_op.alter_column("Quantity", new_column_name="quantity")
batch_op.alter_column("Rate", new_column_name="rate")
batch_op.alter_column("Tax", new_column_name="tax")
batch_op.alter_column("VoucherID", new_column_name="voucher_id")
with op.batch_alter_table("journals") as batch_op:
batch_op.alter_column("Amount", new_column_name="amount")
batch_op.alter_column("CostCentreID", new_column_name="cost_centre_id")
batch_op.alter_column("Debit", new_column_name="debit")
batch_op.alter_column("JournalID", new_column_name="id")
batch_op.alter_column("VoucherID", new_column_name="voucher_id")
with op.batch_alter_table("fingerprints") as batch_op:
batch_op.alter_column("FingerprintID", new_column_name="id")
batch_op.alter_column("Date", new_column_name="date")
batch_op.alter_column("EmployeeID", new_column_name="employee_id")
with op.batch_alter_table("products") as batch_op:
batch_op.alter_column("ProductID", new_column_name="id")
batch_op.alter_column("Code", new_column_name="code")
batch_op.alter_column("Fraction", new_column_name="fraction")
batch_op.alter_column("FractionUnits", new_column_name="fraction_units")
batch_op.alter_column("IsActive", new_column_name="is_active")
batch_op.alter_column("IsFixture", new_column_name="is_fixture")
batch_op.alter_column("Name", new_column_name="name")
batch_op.alter_column("ProductGroupID", new_column_name="product_group_id")
batch_op.alter_column("ProductYield", new_column_name="product_yield")
batch_op.alter_column("Units", new_column_name="units")
with op.batch_alter_table("recipes") as batch_op:
batch_op.alter_column("recipe_id", new_column_name="id")
op.rename_table("salary_deductions", "employee_benefit")
with op.batch_alter_table("employee_benefit") as batch_op:
batch_op.alter_column("SalaryDeductionID", new_column_name="id")
batch_op.alter_column("DaysWorked", new_column_name="days_worked")
batch_op.alter_column("EsiEmployee", new_column_name="esi_employee")
batch_op.alter_column("EsiEmployer", new_column_name="esi_employer")
batch_op.alter_column("GrossSalary", new_column_name="gross_salary")
batch_op.alter_column("JournalID", new_column_name="journal_id")
batch_op.alter_column("PfEmployee", new_column_name="pf_employee")
batch_op.alter_column("PfEmployer", new_column_name="pf_employer")
batch_op.alter_column("VoucherID", new_column_name="voucher_id")
with op.batch_alter_table("vouchers") as batch_op:
batch_op.alter_column("VoucherID", new_column_name="id")
batch_op.alter_column("date", type_=sa.Date(), nullable=False)
batch_op.alter_column("reconcile_date", type_=sa.Date(), nullable=False)
op.rename_table("service_charges", "incentives")
with op.batch_alter_table("employees") as batch_op:
batch_op.alter_column("Designation", new_column_name="designation", nullable=False)
batch_op.alter_column("Salary", new_column_name="salary", nullable=False)
batch_op.alter_column("ServicePoints", new_column_name="points", nullable=False)
batch_op.alter_column(
"JoiningDate", new_column_name="joining_date", type_=sa.Date(), nullable=False,
)
batch_op.alter_column(
"LeavingDate", new_column_name="leaving_date", type_=sa.Date(), nullable=True,
)
with op.batch_alter_table("settings") as batch_op:
batch_op.alter_column("SettingID", new_column_name="id")
batch_op.alter_column("Name", new_column_name="name")
batch_op.alter_column("Data", new_column_name="data")
op.create_unique_constraint(op.f("uq_accounts_name"), "accounts", ["name"])
op.drop_constraint("accounts_name_key", "accounts", type_="unique")
op.create_unique_constraint(op.f("uq_auth_clients_code"), "auth_clients", ["code"])
op.create_unique_constraint(op.f("uq_auth_clients_name"), "auth_clients", ["name"])
op.drop_constraint("auth_clients_Code_key", "auth_clients", type_="unique")
op.drop_constraint("auth_clients_Name_key", "auth_clients", type_="unique")
op.create_unique_constraint(
op.f("uq_auth_login_history_user_id"), "auth_login_history", ["user_id", "client_id", "date"],
)
op.drop_constraint(
"auth_login_history_user_id_client_id_date_key", "auth_login_history", type_="unique",
)
op.create_unique_constraint(op.f("uq_auth_permissions_name"), "auth_permissions", ["name"])
op.drop_constraint("auth_roles_Name_key", "auth_permissions", type_="unique")
op.create_unique_constraint(op.f("uq_auth_roles_name"), "auth_roles", ["name"])
op.drop_constraint("auth_groups_Name_key", "auth_roles", type_="unique")
op.create_unique_constraint(op.f("uq_auth_users_username"), "auth_users", ["username"])
op.drop_constraint("auth_users_Name_key", "auth_users", type_="unique")
op.create_unique_constraint(op.f("uq_cost_centres_name"), "cost_centres", ["name"])
op.drop_constraint("entities_costcenters_Name_key", "cost_centres", type_="unique")
op.drop_constraint("uq_employee_id_date", "fingerprints", type_="unique")
op.create_index(op.f("ix_inventories_voucher_id"), "inventories", ["voucher_id"], unique=False)
op.create_unique_constraint(op.f("uq_inventories_voucher_id"), "inventories", ["voucher_id", "batch_id"])
op.drop_index("ix_inventories_VoucherID", table_name="inventories")
op.create_index(op.f("ix_journals_voucher_id"), "journals", ["voucher_id"], unique=False)
op.drop_index("ix_journals_VoucherID", table_name="journals")
op.create_unique_constraint(op.f("uq_product_groups_name"), "product_groups", ["name"])
op.drop_constraint("entities_productgroups_Name_key", "product_groups", type_="unique")
op.create_unique_constraint(op.f("uq_products_code"), "products", ["code"])
op.create_unique_constraint(op.f("uq_products_name"), "products", ["name", "units"])
op.drop_constraint("products_Code_key", "products", type_="unique")
op.drop_constraint("products_Name_Units_key", "products", type_="unique")
op.create_unique_constraint(op.f("uq_recipe_items_recipe_id"), "recipe_items", ["recipe_id", "product_id"])
op.drop_constraint("recipe_items_recipe_id_product_id_key", "recipe_items", type_="unique")
op.create_unique_constraint(op.f("uq_settings_name"), "settings", ["name"])
op.drop_constraint("settings_Name_key", "settings", type_="unique")
op.create_index(op.f("ix_vouchers_date"), "vouchers", ["date"], unique=False)
op.create_foreign_key(
"fk_incentives_journal_id_journals", "incentives", "journals", ["journal_id"], ["id"],
)
op.create_foreign_key(
"fk_incentives_voucher_id_vouchers", "incentives", "vouchers", ["voucher_id"], ["id"],
)
op.drop_constraint("service_charges_journal_id_fkey", "incentives", type_="foreignkey")
op.drop_constraint("service_charges_voucher_id_fkey", "incentives", type_="foreignkey")
op.create_foreign_key(
"fk_employee_benefit_journal_id_journals", "employee_benefit", "journals", ["journal_id"], ["id"],
)
op.create_foreign_key(
"fk_employee_benefit_voucher_id_vouchers", "employee_benefit", "vouchers", ["voucher_id"], ["id"],
)
op.drop_constraint(
"entities_salarydeductions_JournalID_fkey", "employee_benefit", type_="foreignkey",
)
op.drop_constraint("salary_deductions_VoucherID_fkey", "employee_benefit", type_="foreignkey")
permission = table("auth_permissions", column("id", postgresql.UUID()), column("name", sa.String))
op.execute(
permission.update()
.where(permission.c.name == op.inline_literal("Service Charge"))
.values({"name": op.inline_literal("Incentive")})
)
op.execute(
permission.update()
.where(permission.c.name == op.inline_literal("Salary Deduction"))
.values({"name": op.inline_literal("Employee Benefit")})
)
account = table("accounts", column("name", sa.String))
op.execute(
account.update()
.where(account.c.name == op.inline_literal("Service Charges"))
.values({"name": op.inline_literal("Incentives")})
)
# Remove unneeded Payment and Receipt permissions
permission = table("auth_permissions", column("id", postgresql.UUID()), column("name", sa.String))
role_permission = table(
"role_permissions", column("permission_id", postgresql.UUID()), column("role_id", postgresql.UUID()),
)
op.execute(
role_permission.delete().where(
role_permission.c.permission_id.in_(
select([permission.c.id], permission.c.name.in_(["Payment", "Receipt"]))
)
)
)
op.execute(permission.delete().where(permission.c.name.in_(["Payment", "Receipt"])))
### end Alembic commands ###
def downgrade():
raise Exception("Irreversible migration")

62
brewman/pyproject.toml Normal file
View File

@ -0,0 +1,62 @@
[tool.poetry]
name = "brewman"
version = "8.0.0"
description = "Accounting plus inventory management for a restaurant."
authors = ["tanshu <git@tanshu.com>"]
[tool.poetry.dependencies]
python = "^3.8"
uvicorn = "^0.12.1"
fastapi = "^0.61.1"
python-jose = {extras = ["cryptography"], version = "^3.2.0"}
passlib = {extras = ["bcrypt"], version = "^1.7.3"}
psycopg2-binary = "^2.8.6"
SQLAlchemy = "^1.3.19"
python-multipart = "^0.0.5"
PyJWT = "^1.7.1"
alembic = "^1.4.3"
itsdangerous = "^1.1.0"
python-dotenv = "^0.14.0"
pydantic = {extras = ["dotenv"], version = "^1.6.1"}
starlette = "^0.13.6"
[tool.poetry.dev-dependencies]
flake8 = "^3.8.4"
black = "^20.8b1"
isort = {extras = ["toml"], version = "^5.5.4"}
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.isort]
profile = "black"
atomic = true
include_trailing_comma = true
lines_after_imports = 2
lines_between_types = 1
use_parentheses = true
src_paths = ["poetry", "tests"]
skip_glob = ["*/setup.py"]
filter_files = true
known_first_party = "poetry"
[tool.black]
line-length = 88
include = '\.pyi?$'
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
| tests/.*/setup.py
)/
'''