brewman/alembic/versions/0bf3d70ee7de_initial_commit.py

365 lines
19 KiB
Python

"""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 ###