Initial commit - Mold Cost Calculator Application (Security Fixed)

This commit is contained in:
Gan, Jimmy
2025-06-24 10:28:55 +08:00
commit 9b84cee5be
108 changed files with 15886 additions and 0 deletions
@@ -0,0 +1,72 @@
"""Add cost factor tables
Revision ID: 0b7c21741795
Revises: 0d312b10e473
Create Date: 2025-06-19 09:30:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '0b7c21741795'
down_revision = '0d312b10e473'
branch_labels = None
depends_on = None
def upgrade():
# Create cost_factors table
op.create_table('cost_factors',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('category', sa.String(length=50), nullable=False),
sa.Column('subcategory', sa.String(length=50), nullable=True),
sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('factor_value', sa.Float(), nullable=False),
sa.Column('calculation_formula', sa.String(length=200), nullable=True),
sa.Column('percentage', sa.String(length=20), nullable=True),
sa.Column('description', sa.String(length=500), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('updated_by', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['updated_by'], ['enterprise_users.id'], ),
sa.PrimaryKeyConstraint('id')
)
# Create indexes for cost_factors table
op.create_index('ix_cost_factor_category', 'cost_factors', ['category'], unique=False)
op.create_index('ix_cost_factor_name', 'cost_factors', ['name'], unique=False)
op.create_index('ix_cost_factor_active', 'cost_factors', ['is_active'], unique=False)
# Create cost_factor_history table
op.create_table('cost_factor_history',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('cost_factor_id', sa.Integer(), nullable=False),
sa.Column('old_value', sa.Float(), nullable=True),
sa.Column('new_value', sa.Float(), nullable=False),
sa.Column('changed_by', sa.Integer(), nullable=False),
sa.Column('changed_at', sa.DateTime(), nullable=True),
sa.Column('change_reason', sa.String(length=500), nullable=True),
sa.ForeignKeyConstraint(['changed_by'], ['enterprise_users.id'], ),
sa.ForeignKeyConstraint(['cost_factor_id'], ['cost_factors.id'], ),
sa.PrimaryKeyConstraint('id')
)
# Create indexes for cost_factor_history table
op.create_index('ix_cost_factor_history_factor_id', 'cost_factor_history', ['cost_factor_id'], unique=False)
op.create_index('ix_cost_factor_history_changed_at', 'cost_factor_history', ['changed_at'], unique=False)
def downgrade():
# Drop indexes
op.drop_index('ix_cost_factor_history_changed_at', table_name='cost_factor_history')
op.drop_index('ix_cost_factor_history_factor_id', table_name='cost_factor_history')
op.drop_index('ix_cost_factor_active', table_name='cost_factors')
op.drop_index('ix_cost_factor_name', table_name='cost_factors')
op.drop_index('ix_cost_factor_category', table_name='cost_factors')
# Drop tables
op.drop_table('cost_factor_history')
op.drop_table('cost_factors')
@@ -0,0 +1,92 @@
"""initial
Revision ID: 0d312b10e473
Revises:
Create Date: 2025-06-19 06:45:37.350291
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '0d312b10e473'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('enterprise_users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(length=25), nullable=False),
sa.Column('email', sa.String(length=120), nullable=False),
sa.Column('company', sa.String(length=100), nullable=False),
sa.Column('password_hash', sa.String(length=128), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('password_changed_at', sa.DateTime(), nullable=True),
sa.Column('is_admin', sa.Boolean(), nullable=True),
sa.Column('last_login', sa.DateTime(), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=True),
sa.Column('failed_login_attempts', sa.Integer(), nullable=True),
sa.Column('last_failed_login', sa.DateTime(), nullable=True),
sa.Column('reset_token', sa.String(length=100), nullable=True),
sa.Column('reset_token_expires', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email'),
sa.UniqueConstraint('reset_token'),
sa.UniqueConstraint('username')
)
op.create_table('mold_quotations',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('mold_shop_name', sa.String(length=100), nullable=False),
sa.Column('mold_shop_country', sa.String(length=50), nullable=False),
sa.Column('t1_shoe_factory_name', sa.String(length=100), nullable=False),
sa.Column('t1_shoe_factory_country', sa.String(length=50), nullable=False),
sa.Column('t2_component_factory_name', sa.String(length=100), nullable=False),
sa.Column('t2_component_factory_country', sa.String(length=50), nullable=False),
sa.Column('model_name', sa.String(length=100), nullable=False),
sa.Column('tooling_id', sa.String(length=5), nullable=False),
sa.Column('season', sa.String(length=10), nullable=False),
sa.Column('stage', sa.String(length=10), nullable=False),
sa.Column('type', sa.String(length=20), nullable=False),
sa.Column('issue_date', sa.Date(), nullable=False),
sa.Column('approved_by_mold_shop', sa.String(length=100), nullable=False),
sa.Column('approved_by_t1_tooling', sa.String(length=100), nullable=False),
sa.Column('approved_by_lo_tooling', sa.String(length=100), nullable=False),
sa.Column('mold_main_type', sa.String(length=50), nullable=False),
sa.Column('mold_sub_type', sa.String(length=50), nullable=False),
sa.Column('mold_specific_type', sa.String(length=50), nullable=False),
sa.Column('complexity_high_sidewall', sa.Boolean(), nullable=True),
sa.Column('sliders_count', sa.Integer(), nullable=False),
sa.Column('cavity_count', sa.Float(), nullable=False),
sa.Column('digital_texture_type', sa.String(length=50), nullable=False),
sa.Column('base_price', sa.Float(), nullable=False),
sa.Column('tax_rate', sa.Float(), nullable=True),
sa.Column('total_cost', sa.Float(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('is_archived', sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['enterprise_users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('mold_quotations', schema=None) as batch_op:
batch_op.create_index('ix_quotation_created_at', ['created_at'], unique=False)
batch_op.create_index('ix_quotation_issue_date', ['issue_date'], unique=False)
batch_op.create_index('ix_quotation_user_id', ['user_id'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('mold_quotations', schema=None) as batch_op:
batch_op.drop_index('ix_quotation_user_id')
batch_op.drop_index('ix_quotation_issue_date')
batch_op.drop_index('ix_quotation_created_at')
op.drop_table('mold_quotations')
op.drop_table('enterprise_users')
# ### end Alembic commands ###
@@ -0,0 +1,32 @@
"""increase stage field length
Revision ID: 6adc0a7dbc51
Revises: 0b7c21741795
Create Date: 2025-06-19 18:45:28.923828
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '6adc0a7dbc51'
down_revision = '0b7c21741795'
branch_labels = None
depends_on = None
def upgrade():
# Increase stage field length from VARCHAR(10) to VARCHAR(50)
op.alter_column('mold_quotations', 'stage',
existing_type=sa.VARCHAR(length=10),
type_=sa.VARCHAR(length=50),
existing_nullable=False)
def downgrade():
# Revert stage field length back to VARCHAR(10)
op.alter_column('mold_quotations', 'stage',
existing_type=sa.VARCHAR(length=50),
type_=sa.VARCHAR(length=10),
existing_nullable=False)