Files
xenia-pos-local/local_backend/migrations/versions/0001_v2_baseline.py
T
bonaminandClaude Opus 5.5 d3d328804e refactor(backend): Alembic owns the local schema; v1 ALTER list deleted
Platform v2 step 1.0 (APPS_PLATFORM D-13, D-17).
- migrations/ with env.py (render_as_batch, models/all.py metadata, no
  fileConfig) and baseline 0001_v2_baseline autogenerated from the models and
  reviewed; it also seeds the pos_settings rows a fresh v1 install got
- core/schema.py::upgrade_to_head() is the only way the schema is built:
  app startup, seed.py, demo_seed.py, wipe_database.py and the tests. It
  refuses v1 databases (tables without alembic_version) with a clear error
- main.py: _run_migrations() and create_all removed (723 lines)
- sync_events became a model (was raw DDL); price_event_log order indexes
  declared on the model; unused order_discounts.price_before/after dropped
- tests/guards: no-drift + idempotent upgrade + install defaults + v1 refusal
  + no create_all; placeholders for the time (1.1) and access (1.5) guards
- CS-1 rewritten for Alembic on this branch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 16:54:15 +02:00

1306 lines
64 KiB
Python

"""v2 baseline: the whole local schema as of platform-v2 step 1.0, plus install defaults.
Revision ID: 0001_v2_baseline
Revises:
Create Date: 2026-11-12
Autogenerated from the models on an empty database, then reviewed by hand.
Differences from what a v1 install had (create_all + main.py::_run_migrations):
- sync_events is now a model (models/sync_event.py) instead of raw DDL.
- price_event_log.order_id / order_item_id indexes are declared on the model.
- order_discounts.price_before / price_after are gone: no model or code used them.
- The default table flags and quick-message templates that _run_migrations tried
to insert are NOT seeded: those INSERTs always failed on fresh v1 installs
(NOT NULL columns without defaults), so no install ever had them.
INSTALL_SETTINGS below are the pos_settings rows a fresh v1 install got. Several
readers treat a missing row differently from the default (e.g. the global
discount settings endpoint), so they are kept as install data.
>>> Step 1.3 (module registry: settings declared in manifests with defaults)
>>> should make every reader fall back to declared defaults; then these rows
>>> can stop being seeded.
"""
from datetime import datetime, timezone
from alembic import op
import sqlalchemy as sa
INSTALL_SETTINGS = {
'business_day.force_close_allowed': 'true',
'discounts.enabled': 'true',
'discounts.max_items_per_shift': '',
'discounts.max_total_value_shift': '',
'discounts.max_total_value_workday': '',
'flags.display_mode': 'both',
'orders.auto_close_on_full_payment': 'false',
'orders.bypass_kds_serve': 'false',
'orders.courses': '[]',
'orders.courses_enabled': 'false',
'orders.waiter_cancellations_allowed': 'false',
'orders.waiter_price_adjust_allowed': 'false',
'print.font_extra': '0:0:0',
'print.font_ingredient': '0:0:0',
'print.font_item_name': '16:1:0',
'print.font_item_note': '0:0:0',
'print.font_meta': '0:0:0',
'print.font_order_note': '0:1:0',
'print.font_order_number': '48:1:0',
'print.font_pref': '0:0:0',
'print.font_quick': '0:0:0',
'print.ticket_mode': 'detailed',
'security.auto_lock': 'false',
'security.auto_lock_seconds': '300',
'security.auto_logout': 'false',
'security.auto_logout_seconds': '1800',
'security.autofill_username': 'true',
'security.login_method': 'password',
'shifts.hide_revenue_from_waiters': 'false',
'shifts.waiter_self_end': 'true',
'shifts.waiter_self_start': 'true',
'venue.name': '',
'venue.type': '',
}
revision = '0001_v2_baseline'
down_revision = None
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('categories',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('color', sa.String(), nullable=True),
sa.Column('sort_order', sa.Integer(), nullable=True),
sa.Column('parent_id', sa.Integer(), nullable=True),
sa.Column('general_sort_order', sa.Integer(), nullable=False),
sa.Column('auto_expanded', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['parent_id'], ['categories.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('categories', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_categories_id'), ['id'], unique=False)
op.create_table('contacts',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('type', sa.String(), nullable=False),
sa.Column('phone', sa.String(), nullable=True),
sa.Column('email', sa.String(), nullable=True),
sa.Column('address', sa.Text(), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('contacts', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_contacts_id'), ['id'], unique=False)
op.create_table('printers',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('ip_address', sa.String(), nullable=False),
sa.Column('port', sa.Integer(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('protocol', sa.String(), nullable=False),
sa.Column('line_width', sa.Integer(), nullable=False),
sa.Column('duplicates', sa.Integer(), nullable=False),
sa.Column('codepage_n', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('printers', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_printers_id'), ['id'], unique=False)
op.create_table('quick_message_templates',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('body', sa.String(), nullable=False),
sa.Column('sort_order', sa.Integer(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('quick_message_templates', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_quick_message_templates_id'), ['id'], unique=False)
op.create_table('sync_events',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('event_type', sa.String(), nullable=False),
sa.Column('payload', sa.Text(), nullable=False),
sa.Column('target_user_ids', sa.Text(), nullable=True),
sa.Column('created_at', sa.String(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sqlite_autoincrement=True
)
with op.batch_alter_table('sync_events', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_sync_events_created_at'), ['created_at'], unique=False)
op.create_table('table_flag_defs',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('emoji', sa.String(), nullable=True),
sa.Column('color', sa.String(), nullable=True),
sa.Column('text_color', sa.String(), nullable=True),
sa.Column('sort_order', sa.Integer(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('table_flag_defs', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_table_flag_defs_id'), ['id'], unique=False)
op.create_table('table_groups',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('prefix', sa.String(), nullable=True),
sa.Column('sort_order', sa.Integer(), nullable=True),
sa.Column('color', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
with op.batch_alter_table('table_groups', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_table_groups_id'), ['id'], unique=False)
op.create_table('users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(), nullable=False),
sa.Column('pin_hash', sa.String(), nullable=False),
sa.Column('password_hash', sa.String(), nullable=True),
sa.Column('email', sa.String(), nullable=True),
sa.Column('role', sa.String(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('full_name', sa.String(), nullable=True),
sa.Column('nickname', sa.String(), nullable=True),
sa.Column('mobile_phone', sa.String(), nullable=True),
sa.Column('note', sa.String(), nullable=True),
sa.Column('avatar_url', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('hourly_rate', sa.Float(), nullable=True),
sa.Column('perm_access_dashboard', sa.Boolean(), nullable=False),
sa.Column('perm_access_waiter_app', sa.Boolean(), nullable=False),
sa.Column('perm_access_kds', sa.Boolean(), nullable=False),
sa.Column('perm_cancel_orders', sa.Boolean(), nullable=False),
sa.Column('perm_apply_discounts', sa.Boolean(), nullable=False),
sa.Column('perm_modify_prices', sa.Boolean(), nullable=False),
sa.Column('perm_open_orders', sa.Boolean(), nullable=False),
sa.Column('perm_close_orders', sa.Boolean(), nullable=False),
sa.Column('perm_view_reports', sa.Boolean(), nullable=False),
sa.Column('perm_manage_staff', sa.Boolean(), nullable=False),
sa.Column('perm_manage_tables', sa.Boolean(), nullable=False),
sa.Column('perm_manage_menu', sa.Boolean(), nullable=False),
sa.Column('perm_manage_settings', sa.Boolean(), nullable=False),
sa.Column('waiter_settings', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_users_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_users_username'), ['username'], unique=True)
op.create_table('assistant_assignments',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('primary_waiter_id', sa.Integer(), nullable=False),
sa.Column('assistant_waiter_id', sa.Integer(), nullable=False),
sa.Column('assigned_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['assistant_waiter_id'], ['users.id'], ),
sa.ForeignKeyConstraint(['primary_waiter_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('assistant_assignments', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_assistant_assignments_id'), ['id'], unique=False)
op.create_table('business_days',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('status', sa.String(), nullable=False),
sa.Column('opened_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('opened_by_id', sa.Integer(), nullable=False),
sa.Column('closed_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('closed_by_id', sa.Integer(), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('store_opening_cash', sa.Float(), nullable=True),
sa.Column('store_closing_cash', sa.Float(), nullable=True),
sa.Column('store_cash_discrepancy', sa.Float(), nullable=True),
sa.ForeignKeyConstraint(['closed_by_id'], ['users.id'], ),
sa.ForeignKeyConstraint(['opened_by_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('business_days', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_business_days_id'), ['id'], unique=False)
op.create_table('conversations',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('type', sa.String(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('is_system', sa.Boolean(), nullable=False),
sa.Column('created_by', sa.Integer(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['created_by'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('conversations', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_conversations_id'), ['id'], unique=False)
op.create_table('customers',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('nickname', sa.String(), nullable=True),
sa.Column('phone', sa.String(), nullable=True),
sa.Column('email', sa.String(), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['created_by_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('customers', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_customers_id'), ['id'], unique=False)
op.create_table('pos_settings',
sa.Column('key', sa.String(), nullable=False),
sa.Column('value', sa.String(), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('updated_by_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['updated_by_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('key')
)
op.create_table('prep_zones',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('description', sa.String(), nullable=True),
sa.Column('notification_name', sa.String(), nullable=True),
sa.Column('auto_print', sa.String(), nullable=False),
sa.Column('master_printer_id', sa.Integer(), nullable=True),
sa.Column('master_copies', sa.Integer(), nullable=False),
sa.Column('secondary_copies', sa.Integer(), nullable=False),
sa.Column('print_copies', sa.Integer(), nullable=False),
sa.Column('sort_items_by', sa.String(), nullable=False),
sa.Column('group_by_category', sa.Integer(), nullable=False),
sa.Column('category_order', sa.String(), nullable=False),
sa.Column('print_checkboxes', sa.Integer(), nullable=False),
sa.Column('bypass_pending', sa.Integer(), nullable=False),
sa.Column('bypass_kds', sa.Integer(), nullable=False),
sa.Column('auto_ready_to_served', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['master_printer_id'], ['printers.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('prep_zones', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_prep_zones_id'), ['id'], unique=False)
op.create_table('price_groups',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('color', sa.String(), nullable=True),
sa.Column('is_active', sa.Integer(), nullable=False),
sa.Column('auto_enable_time', sa.String(), nullable=True),
sa.Column('auto_disable_time', sa.String(), nullable=True),
sa.Column('auto_days', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_by', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['created_by'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('price_groups', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_price_groups_id'), ['id'], unique=False)
op.create_table('products',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('category_id', sa.Integer(), nullable=True),
sa.Column('base_price', sa.Float(), nullable=False),
sa.Column('is_available', sa.Boolean(), nullable=False),
sa.Column('lifecycle_status', sa.String(), nullable=False),
sa.Column('printer_zone_id', sa.Integer(), nullable=True),
sa.Column('image_url', sa.String(), nullable=True),
sa.Column('sort_order', sa.Integer(), nullable=False),
sa.Column('digital_visible', sa.Integer(), nullable=False),
sa.Column('digital_available', sa.Integer(), nullable=False),
sa.Column('digital_name', sa.String(), nullable=True),
sa.Column('digital_description', sa.String(), nullable=True),
sa.Column('digital_price', sa.Float(), nullable=True),
sa.Column('digital_discount', sa.Float(), nullable=False),
sa.Column('digital_image_url', sa.String(), nullable=True),
sa.Column('cloud_image_hash', sa.String(), nullable=True),
sa.Column('unit_type', sa.String(), nullable=False),
sa.Column('cost_simple', sa.Float(), nullable=True),
sa.Column('cost_breakdown', sa.Text(), nullable=True),
sa.Column('quick_add_enabled', sa.Boolean(), nullable=False),
sa.Column('is_service_item', sa.Boolean(), nullable=False),
sa.Column('tags', sa.Text(), nullable=True),
sa.Column('fiscal_name', sa.String(), nullable=True),
sa.Column('fiscal_vat_group_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['category_id'], ['categories.id'], ),
sa.ForeignKeyConstraint(['printer_zone_id'], ['printers.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('products', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_products_id'), ['id'], unique=False)
op.create_table('recovery_codes',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('code_hash', sa.String(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('used_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('recovery_codes', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_recovery_codes_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_recovery_codes_user_id'), ['user_id'], unique=False)
op.create_table('scheduled_shifts',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('scheduled_date', sa.Date(), nullable=False),
sa.Column('start_time', sa.String(), nullable=False),
sa.Column('end_time', sa.String(), nullable=False),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['created_by_id'], ['users.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('scheduled_shifts', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_scheduled_shifts_id'), ['id'], unique=False)
op.create_table('site_notes',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('body', sa.Text(), nullable=False),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('is_pinned', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['created_by_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('site_notes', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_site_notes_id'), ['id'], unique=False)
op.create_table('site_todos',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('body', sa.Text(), nullable=False),
sa.Column('is_done', sa.Boolean(), nullable=False),
sa.Column('done_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('done_by_id', sa.Integer(), nullable=True),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('priority', sa.String(), nullable=False),
sa.ForeignKeyConstraint(['created_by_id'], ['users.id'], ),
sa.ForeignKeyConstraint(['done_by_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('site_todos', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_site_todos_id'), ['id'], unique=False)
op.create_table('staff_messages',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('sender_id', sa.Integer(), nullable=False),
sa.Column('body', sa.Text(), nullable=False),
sa.Column('target_waiter_ids', sa.Text(), nullable=False),
sa.Column('table_ids', sa.Text(), nullable=False),
sa.Column('message_type', sa.String(), nullable=False),
sa.Column('kds_zone', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['sender_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('staff_messages', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_staff_messages_id'), ['id'], unique=False)
op.create_table('tables',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('number', sa.Integer(), nullable=False),
sa.Column('label', sa.String(), nullable=True),
sa.Column('group_id', sa.Integer(), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('seat_count', sa.Integer(), nullable=True),
sa.Column('floor_x', sa.Float(), nullable=True),
sa.Column('floor_y', sa.Float(), nullable=True),
sa.ForeignKeyConstraint(['group_id'], ['table_groups.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('tables', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_tables_id'), ['id'], unique=False)
op.create_table('waiter_discount_settings',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('can_apply_discounts', sa.Integer(), nullable=False),
sa.Column('max_discount_percent', sa.Float(), nullable=True),
sa.Column('max_discount_amount', sa.Float(), nullable=True),
sa.Column('max_total_value_shift', sa.Float(), nullable=True),
sa.Column('max_total_value_workday', sa.Float(), nullable=True),
sa.Column('max_items_per_shift', sa.Integer(), nullable=True),
sa.Column('max_items_per_workday', sa.Integer(), nullable=True),
sa.Column('max_items_per_order', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('user_id')
)
with op.batch_alter_table('waiter_discount_settings', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_waiter_discount_settings_id'), ['id'], unique=False)
op.create_table('waiter_zones',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('waiter_id', sa.Integer(), nullable=False),
sa.Column('group_id', sa.Integer(), nullable=True),
sa.Column('assigned_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['group_id'], ['table_groups.id'], ),
sa.ForeignKeyConstraint(['waiter_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('waiter_zones', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_waiter_zones_id'), ['id'], unique=False)
op.create_table('chat_messages',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('conversation_id', sa.Integer(), nullable=False),
sa.Column('sender_id', sa.Integer(), nullable=False),
sa.Column('body', sa.Text(), nullable=False),
sa.Column('sent_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['conversation_id'], ['conversations.id'], ),
sa.ForeignKeyConstraint(['sender_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('chat_messages', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_chat_messages_id'), ['id'], unique=False)
op.create_table('conversation_participants',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('conversation_id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('joined_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('last_read_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['conversation_id'], ['conversations.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('conversation_participants', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_conversation_participants_id'), ['id'], unique=False)
op.create_table('expenses',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('description', sa.String(), nullable=False),
sa.Column('category', sa.String(), nullable=False),
sa.Column('contact_id', sa.Integer(), nullable=True),
sa.Column('total_amount', sa.Float(), nullable=False),
sa.Column('paid_amount', sa.Float(), nullable=False),
sa.Column('due_date', sa.DateTime(timezone=True), nullable=True),
sa.Column('business_day_id', sa.Integer(), nullable=True),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.ForeignKeyConstraint(['business_day_id'], ['business_days.id'], ),
sa.ForeignKeyConstraint(['contact_id'], ['contacts.id'], ),
sa.ForeignKeyConstraint(['created_by_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('expenses', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_expenses_id'), ['id'], unique=False)
op.create_table('orders',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('table_id', sa.Integer(), nullable=True),
sa.Column('opened_by', sa.Integer(), nullable=False),
sa.Column('opened_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('status', sa.String(), nullable=False),
sa.Column('closed_at', sa.DateTime(), nullable=True),
sa.Column('closed_by', sa.Integer(), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('business_day_id', sa.Integer(), nullable=True),
sa.Column('kds_status', sa.String(), nullable=False),
sa.Column('kds_status_changed_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('order_type', sa.String(), nullable=False),
sa.Column('source', sa.String(), nullable=False),
sa.Column('online_order_ref', sa.String(), nullable=True),
sa.Column('online_order_cloud_id', sa.Integer(), nullable=True),
sa.Column('online_status', sa.String(), nullable=True),
sa.Column('online_customer_name', sa.String(), nullable=True),
sa.Column('online_customer_phone', sa.String(), nullable=True),
sa.Column('online_customer_address', sa.Text(), nullable=True),
sa.Column('online_customer_notes', sa.Text(), nullable=True),
sa.Column('online_order_type', sa.String(), nullable=True),
sa.Column('customer_id', sa.Integer(), nullable=True),
sa.Column('customer_count', sa.Integer(), nullable=True),
sa.Column('fiscal_status', sa.String(), nullable=True),
sa.ForeignKeyConstraint(['business_day_id'], ['business_days.id'], ),
sa.ForeignKeyConstraint(['closed_by'], ['users.id'], ),
sa.ForeignKeyConstraint(['customer_id'], ['customers.id'], ),
sa.ForeignKeyConstraint(['opened_by'], ['users.id'], ),
sa.ForeignKeyConstraint(['table_id'], ['tables.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('orders', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_orders_id'), ['id'], unique=False)
op.create_table('prep_zone_printers',
sa.Column('prep_zone_id', sa.Integer(), nullable=False),
sa.Column('printer_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['prep_zone_id'], ['prep_zones.id'], ),
sa.ForeignKeyConstraint(['printer_id'], ['printers.id'], ),
sa.PrimaryKeyConstraint('prep_zone_id', 'printer_id')
)
op.create_table('price_modifiers',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('color', sa.String(), nullable=True),
sa.Column('is_active', sa.Integer(), nullable=False),
sa.Column('is_favorite', sa.Integer(), nullable=False),
sa.Column('allow_stack', sa.Integer(), nullable=False),
sa.Column('sort_order', sa.Integer(), nullable=False),
sa.Column('scope', sa.String(), nullable=False),
sa.Column('item_id', sa.Integer(), nullable=True),
sa.Column('action_type', sa.String(), nullable=False),
sa.Column('action_value', sa.Float(), nullable=False),
sa.Column('round_to', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_by', sa.Integer(), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('updated_by', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['created_by'], ['users.id'], ),
sa.ForeignKeyConstraint(['item_id'], ['products.id'], ),
sa.ForeignKeyConstraint(['updated_by'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('price_modifiers', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_price_modifiers_id'), ['id'], unique=False)
op.create_table('product_modifier_groups',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('product_id', sa.Integer(), nullable=False),
sa.Column('modifier_type', sa.String(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('sort_order', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('product_modifier_groups', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_product_modifier_groups_id'), ['id'], unique=False)
op.create_table('product_prep_zones',
sa.Column('product_id', sa.Integer(), nullable=False),
sa.Column('prep_zone_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['prep_zone_id'], ['prep_zones.id'], ),
sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
sa.PrimaryKeyConstraint('product_id', 'prep_zone_id')
)
op.create_table('product_quick_options',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('product_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('price', sa.Float(), nullable=False),
sa.Column('allow_multiple', sa.Boolean(), nullable=False),
sa.Column('sort_order', sa.Integer(), nullable=False),
sa.Column('is_favorite', sa.Boolean(), nullable=False),
sa.Column('favorite_sort_order', sa.Integer(), nullable=False),
sa.Column('is_compact', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('product_quick_options', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_product_quick_options_id'), ['id'], unique=False)
op.create_table('reservations',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('guest_name', sa.String(), nullable=False),
sa.Column('party_size', sa.Integer(), nullable=False),
sa.Column('phone', sa.String(), nullable=True),
sa.Column('email', sa.String(), nullable=True),
sa.Column('note', sa.Text(), nullable=True),
sa.Column('reserved_for', sa.DateTime(), nullable=False),
sa.Column('table_id', sa.Integer(), nullable=True),
sa.Column('status', sa.String(), nullable=False),
sa.Column('source', sa.String(), nullable=False),
sa.Column('created_by_user_id', sa.Integer(), nullable=True),
sa.Column('online_customer_id', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['created_by_user_id'], ['users.id'], ),
sa.ForeignKeyConstraint(['table_id'], ['tables.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('reservations', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_reservations_id'), ['id'], unique=False)
op.create_table('staff_message_acks',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('message_id', sa.Integer(), nullable=False),
sa.Column('waiter_id', sa.Integer(), nullable=False),
sa.Column('acked_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['message_id'], ['staff_messages.id'], ),
sa.ForeignKeyConstraint(['waiter_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('staff_message_acks', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_staff_message_acks_id'), ['id'], unique=False)
op.create_table('table_flag_assignments',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('table_id', sa.Integer(), nullable=False),
sa.Column('flag_id', sa.Integer(), nullable=False),
sa.Column('assigned_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('assigned_by', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['assigned_by'], ['users.id'], ),
sa.ForeignKeyConstraint(['flag_id'], ['table_flag_defs.id'], ),
sa.ForeignKeyConstraint(['table_id'], ['tables.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('table_flag_assignments', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_table_flag_assignments_id'), ['id'], unique=False)
op.create_table('tabs',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('customer_id', sa.Integer(), nullable=False),
sa.Column('status', sa.String(), nullable=False),
sa.Column('opened_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('closed_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('closed_by_id', sa.Integer(), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.ForeignKeyConstraint(['closed_by_id'], ['users.id'], ),
sa.ForeignKeyConstraint(['customer_id'], ['customers.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('tabs', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_tabs_id'), ['id'], unique=False)
op.create_table('waiter_shifts',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('waiter_id', sa.Integer(), nullable=False),
sa.Column('business_day_id', sa.Integer(), nullable=False),
sa.Column('started_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('ended_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('starting_cash', sa.Float(), nullable=True),
sa.Column('total_collected', sa.Float(), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('hourly_rate_snapshot', sa.Float(), nullable=True),
sa.Column('counted_cash_end', sa.Float(), nullable=True),
sa.Column('cash_discrepancy', sa.Float(), nullable=True),
sa.ForeignKeyConstraint(['business_day_id'], ['business_days.id'], ),
sa.ForeignKeyConstraint(['waiter_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('waiter_shifts', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_waiter_shifts_id'), ['id'], unique=False)
op.create_table('waste_log',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('product_id', sa.Integer(), nullable=False),
sa.Column('quantity', sa.Float(), nullable=False),
sa.Column('unit_cost_snapshot', sa.Float(), nullable=True),
sa.Column('total_cost', sa.Float(), nullable=True),
sa.Column('reason', sa.String(), nullable=False),
sa.Column('reason_notes', sa.Text(), nullable=True),
sa.Column('logged_by_id', sa.Integer(), nullable=False),
sa.Column('business_day_id', sa.Integer(), nullable=True),
sa.Column('logged_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['business_day_id'], ['business_days.id'], ),
sa.ForeignKeyConstraint(['logged_by_id'], ['users.id'], ),
sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('waste_log', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_waste_log_id'), ['id'], unique=False)
op.create_table('deals',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('color', sa.String(), nullable=True),
sa.Column('is_active', sa.Integer(), nullable=False),
sa.Column('sort_order', sa.Integer(), nullable=False),
sa.Column('action_type', sa.String(), nullable=False),
sa.Column('action_modifier_id', sa.Integer(), nullable=True),
sa.Column('action_value', sa.Float(), nullable=True),
sa.Column('action_free_item_id', sa.Integer(), nullable=True),
sa.Column('action_free_target_type', sa.String(), nullable=True),
sa.Column('action_free_target_ids', sa.Text(), nullable=True),
sa.Column('action_free_quantity', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_by', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['action_free_item_id'], ['products.id'], ),
sa.ForeignKeyConstraint(['action_modifier_id'], ['price_modifiers.id'], ),
sa.ForeignKeyConstraint(['created_by'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('deals', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_deals_id'), ['id'], unique=False)
op.create_table('expense_payments',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('expense_id', sa.Integer(), nullable=False),
sa.Column('amount', sa.Float(), nullable=False),
sa.Column('paid_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('paid_by_id', sa.Integer(), nullable=False),
sa.Column('notes', sa.Text(), nullable=True),
sa.ForeignKeyConstraint(['expense_id'], ['expenses.id'], ),
sa.ForeignKeyConstraint(['paid_by_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('expense_payments', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_expense_payments_id'), ['id'], unique=False)
op.create_table('order_audit_log',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('order_id', sa.Integer(), nullable=False),
sa.Column('event_type', sa.String(), nullable=False),
sa.Column('waiter_id', sa.Integer(), nullable=True),
sa.Column('item_ids', sa.Text(), nullable=True),
sa.Column('amount', sa.Float(), nullable=True),
sa.Column('payment_method', sa.String(), nullable=True),
sa.Column('note', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('offline_uuid', sa.String(), nullable=True),
sa.Column('offline_at', sa.String(), nullable=True),
sa.Column('is_duplicate', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['order_id'], ['orders.id'], ),
sa.ForeignKeyConstraint(['waiter_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('order_audit_log', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_order_audit_log_id'), ['id'], unique=False)
op.create_table('order_waiters',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('order_id', sa.Integer(), nullable=False),
sa.Column('waiter_id', sa.Integer(), nullable=False),
sa.Column('assigned_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['order_id'], ['orders.id'], ),
sa.ForeignKeyConstraint(['waiter_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('order_waiters', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_order_waiters_id'), ['id'], unique=False)
op.create_table('price_modifier_conditions',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('modifier_id', sa.Integer(), nullable=False),
sa.Column('condition_type', sa.String(), nullable=False),
sa.Column('params', sa.Text(), nullable=False),
sa.ForeignKeyConstraint(['modifier_id'], ['price_modifiers.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('price_modifier_conditions', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_price_modifier_conditions_id'), ['id'], unique=False)
op.create_table('price_modifier_targets',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('modifier_id', sa.Integer(), nullable=False),
sa.Column('target_type', sa.String(), nullable=False),
sa.Column('target_id', sa.Integer(), nullable=True),
sa.Column('target_tag', sa.String(), nullable=True),
sa.Column('target_ids', sa.Text(), nullable=True),
sa.Column('target_tags', sa.Text(), nullable=True),
sa.ForeignKeyConstraint(['modifier_id'], ['price_modifiers.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('price_modifier_targets', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_price_modifier_targets_id'), ['id'], unique=False)
op.create_table('print_jobs',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('order_id', sa.Integer(), nullable=False),
sa.Column('printer_id', sa.Integer(), nullable=False),
sa.Column('zone_id', sa.Integer(), nullable=True),
sa.Column('item_ids', sa.Text(), nullable=False),
sa.Column('copies', sa.Integer(), nullable=False),
sa.Column('status', sa.String(), nullable=False),
sa.Column('retry_count', sa.Integer(), nullable=False),
sa.Column('first_attempted_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('last_attempted_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('succeeded_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('cancelled_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('cancel_reason', sa.String(), nullable=True),
sa.ForeignKeyConstraint(['order_id'], ['orders.id'], ),
sa.ForeignKeyConstraint(['printer_id'], ['printers.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('print_jobs', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_print_jobs_id'), ['id'], unique=False)
op.create_table('print_log',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('order_id', sa.Integer(), nullable=False),
sa.Column('printer_id', sa.Integer(), nullable=False),
sa.Column('printed_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('item_ids', sa.Text(), nullable=False),
sa.Column('success', sa.Boolean(), nullable=False),
sa.Column('error_message', sa.Text(), nullable=True),
sa.ForeignKeyConstraint(['order_id'], ['orders.id'], ),
sa.ForeignKeyConstraint(['printer_id'], ['printers.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('print_log', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_print_log_id'), ['id'], unique=False)
op.create_table('product_ingredients',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('product_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('extra_cost', sa.Float(), nullable=True),
sa.Column('is_favorite', sa.Boolean(), nullable=False),
sa.Column('favorite_sort_order', sa.Integer(), nullable=False),
sa.Column('is_compact', sa.Boolean(), nullable=False),
sa.Column('group_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['group_id'], ['product_modifier_groups.id'], ),
sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('product_ingredients', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_product_ingredients_id'), ['id'], unique=False)
op.create_table('product_options',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('product_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('extra_cost', sa.Float(), nullable=True),
sa.Column('allow_multiple', sa.Boolean(), nullable=False),
sa.Column('multi_select', sa.Boolean(), nullable=False),
sa.Column('sub_choices', sa.Text(), nullable=True),
sa.Column('is_favorite', sa.Boolean(), nullable=False),
sa.Column('favorite_sort_order', sa.Integer(), nullable=False),
sa.Column('is_compact', sa.Boolean(), nullable=False),
sa.Column('group_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['group_id'], ['product_modifier_groups.id'], ),
sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('product_options', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_product_options_id'), ['id'], unique=False)
op.create_table('product_preference_sets',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('product_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('default_choice_id', sa.Integer(), nullable=True),
sa.Column('shared_subset', sa.Text(), nullable=True),
sa.Column('is_favorite', sa.Boolean(), nullable=False),
sa.Column('favorite_sort_order', sa.Integer(), nullable=False),
sa.Column('group_id', sa.Integer(), nullable=True),
sa.Column('allow_multi_select', sa.Boolean(), nullable=False),
sa.Column('allow_choice_quantity', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['group_id'], ['product_modifier_groups.id'], ),
sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('product_preference_sets', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_product_preference_sets_id'), ['id'], unique=False)
op.create_table('shift_breaks',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('shift_id', sa.Integer(), nullable=False),
sa.Column('started_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('ended_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['shift_id'], ['waiter_shifts.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('shift_breaks', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_shift_breaks_id'), ['id'], unique=False)
op.create_table('tab_payments',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('tab_id', sa.Integer(), nullable=False),
sa.Column('amount', sa.Float(), nullable=False),
sa.Column('payment_method', sa.String(), nullable=True),
sa.Column('received_by_id', sa.Integer(), nullable=False),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['received_by_id'], ['users.id'], ),
sa.ForeignKeyConstraint(['tab_id'], ['tabs.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('tab_payments', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_tab_payments_id'), ['id'], unique=False)
op.create_table('deal_conditions',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('deal_id', sa.Integer(), nullable=False),
sa.Column('condition_type', sa.String(), nullable=False),
sa.Column('params', sa.Text(), nullable=False),
sa.ForeignKeyConstraint(['deal_id'], ['deals.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('deal_conditions', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_deal_conditions_id'), ['id'], unique=False)
op.create_table('deal_targets',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('deal_id', sa.Integer(), nullable=False),
sa.Column('target_type', sa.String(), nullable=False),
sa.Column('target_id', sa.Integer(), nullable=True),
sa.Column('target_tag', sa.String(), nullable=True),
sa.Column('target_ids', sa.Text(), nullable=True),
sa.Column('target_tags', sa.Text(), nullable=True),
sa.ForeignKeyConstraint(['deal_id'], ['deals.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('deal_targets', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_deal_targets_id'), ['id'], unique=False)
op.create_table('order_items',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('order_id', sa.Integer(), nullable=False),
sa.Column('product_id', sa.Integer(), nullable=False),
sa.Column('added_by', sa.Integer(), nullable=False),
sa.Column('quantity', sa.Float(), nullable=False),
sa.Column('unit_price', sa.Float(), nullable=False),
sa.Column('selected_options', sa.Text(), nullable=True),
sa.Column('removed_ingredients', sa.Text(), nullable=True),
sa.Column('notes', sa.Text(), nullable=True),
sa.Column('status', sa.String(), nullable=False),
sa.Column('kds_status', sa.String(), nullable=False),
sa.Column('added_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('printed', sa.Boolean(), nullable=False),
sa.Column('paid_by', sa.Integer(), nullable=True),
sa.Column('paid_at', sa.DateTime(), nullable=True),
sa.Column('payment_method', sa.String(), nullable=True),
sa.Column('paid_in_shift_id', sa.Integer(), nullable=True),
sa.Column('unit_cost', sa.Float(), nullable=True),
sa.Column('price_adjustment', sa.Float(), nullable=False),
sa.Column('cancelled_by', sa.Integer(), nullable=True),
sa.Column('cancelled_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('cancel_reason', sa.Text(), nullable=True),
sa.Column('decline_note', sa.Text(), nullable=True),
sa.Column('course_id', sa.Integer(), nullable=True),
sa.Column('deal_id', sa.Integer(), nullable=True),
sa.Column('linked_item_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['added_by'], ['users.id'], ),
sa.ForeignKeyConstraint(['cancelled_by'], ['users.id'], ),
sa.ForeignKeyConstraint(['deal_id'], ['deals.id'], ),
sa.ForeignKeyConstraint(['linked_item_id'], ['order_items.id'], ),
sa.ForeignKeyConstraint(['order_id'], ['orders.id'], ),
sa.ForeignKeyConstraint(['paid_by'], ['users.id'], ),
sa.ForeignKeyConstraint(['paid_in_shift_id'], ['waiter_shifts.id'], ),
sa.ForeignKeyConstraint(['product_id'], ['products.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('order_items', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_order_items_id'), ['id'], unique=False)
op.create_table('product_preference_choices',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('set_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('extra_cost', sa.Float(), nullable=True),
sa.Column('sub_choices', sa.Text(), nullable=True),
sa.Column('disables_subset', sa.Boolean(), nullable=False),
sa.Column('is_compact', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['set_id'], ['product_preference_sets.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('product_preference_choices', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_product_preference_choices_id'), ['id'], unique=False)
op.create_table('order_discounts',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('order_id', sa.Integer(), nullable=False),
sa.Column('item_id', sa.Integer(), nullable=True),
sa.Column('discount_type', sa.String(), nullable=False),
sa.Column('discount_value', sa.Float(), nullable=False),
sa.Column('applied_by', sa.Integer(), nullable=False),
sa.Column('applied_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('reason', sa.Text(), nullable=True),
sa.ForeignKeyConstraint(['applied_by'], ['users.id'], ),
sa.ForeignKeyConstraint(['item_id'], ['order_items.id'], ),
sa.ForeignKeyConstraint(['order_id'], ['orders.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('order_discounts', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_order_discounts_id'), ['id'], unique=False)
op.create_table('price_event_log',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('order_id', sa.Integer(), nullable=False),
sa.Column('order_item_id', sa.Integer(), nullable=True),
sa.Column('event_type', sa.String(), nullable=False),
sa.Column('modifier_id', sa.Integer(), nullable=True),
sa.Column('deal_id', sa.Integer(), nullable=True),
sa.Column('price_before', sa.Float(), nullable=True),
sa.Column('price_after', sa.Float(), nullable=True),
sa.Column('delta_amount', sa.Float(), nullable=True),
sa.Column('applied_by_user_id', sa.Integer(), nullable=True),
sa.Column('waiter_note', sa.Text(), nullable=True),
sa.Column('conditions_snapshot', sa.Text(), nullable=True),
sa.Column('selected_item_ids', sa.Text(), nullable=True),
sa.Column('applied_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['applied_by_user_id'], ['users.id'], ),
sa.ForeignKeyConstraint(['deal_id'], ['deals.id'], ),
sa.ForeignKeyConstraint(['modifier_id'], ['price_modifiers.id'], ),
sa.ForeignKeyConstraint(['order_id'], ['orders.id'], ),
sa.ForeignKeyConstraint(['order_item_id'], ['order_items.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('price_event_log', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_price_event_log_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_price_event_log_order_id'), ['order_id'], unique=False)
batch_op.create_index(batch_op.f('ix_price_event_log_order_item_id'), ['order_item_id'], unique=False)
op.create_table('tab_entries',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('tab_id', sa.Integer(), nullable=False),
sa.Column('order_id', sa.Integer(), nullable=True),
sa.Column('order_item_id', sa.Integer(), nullable=True),
sa.Column('amount', sa.Float(), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['created_by_id'], ['users.id'], ),
sa.ForeignKeyConstraint(['order_id'], ['orders.id'], ),
sa.ForeignKeyConstraint(['order_item_id'], ['order_items.id'], ),
sa.ForeignKeyConstraint(['tab_id'], ['tabs.id'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('tab_entries', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_tab_entries_id'), ['id'], unique=False)
# ### end Alembic commands ###
settings_table = sa.table(
"pos_settings",
sa.column("key", sa.String), sa.column("value", sa.String), sa.column("updated_at", sa.DateTime(timezone=True)),
)
now = datetime.now(timezone.utc)
op.bulk_insert(settings_table, [{"key": k, "value": v, "updated_at": now} for k, v in INSTALL_SETTINGS.items()])
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('tab_entries', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_tab_entries_id'))
op.drop_table('tab_entries')
with op.batch_alter_table('price_event_log', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_price_event_log_order_item_id'))
batch_op.drop_index(batch_op.f('ix_price_event_log_order_id'))
batch_op.drop_index(batch_op.f('ix_price_event_log_id'))
op.drop_table('price_event_log')
with op.batch_alter_table('order_discounts', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_order_discounts_id'))
op.drop_table('order_discounts')
with op.batch_alter_table('product_preference_choices', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_product_preference_choices_id'))
op.drop_table('product_preference_choices')
with op.batch_alter_table('order_items', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_order_items_id'))
op.drop_table('order_items')
with op.batch_alter_table('deal_targets', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_deal_targets_id'))
op.drop_table('deal_targets')
with op.batch_alter_table('deal_conditions', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_deal_conditions_id'))
op.drop_table('deal_conditions')
with op.batch_alter_table('tab_payments', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_tab_payments_id'))
op.drop_table('tab_payments')
with op.batch_alter_table('shift_breaks', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_shift_breaks_id'))
op.drop_table('shift_breaks')
with op.batch_alter_table('product_preference_sets', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_product_preference_sets_id'))
op.drop_table('product_preference_sets')
with op.batch_alter_table('product_options', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_product_options_id'))
op.drop_table('product_options')
with op.batch_alter_table('product_ingredients', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_product_ingredients_id'))
op.drop_table('product_ingredients')
with op.batch_alter_table('print_log', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_print_log_id'))
op.drop_table('print_log')
with op.batch_alter_table('print_jobs', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_print_jobs_id'))
op.drop_table('print_jobs')
with op.batch_alter_table('price_modifier_targets', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_price_modifier_targets_id'))
op.drop_table('price_modifier_targets')
with op.batch_alter_table('price_modifier_conditions', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_price_modifier_conditions_id'))
op.drop_table('price_modifier_conditions')
with op.batch_alter_table('order_waiters', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_order_waiters_id'))
op.drop_table('order_waiters')
with op.batch_alter_table('order_audit_log', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_order_audit_log_id'))
op.drop_table('order_audit_log')
with op.batch_alter_table('expense_payments', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_expense_payments_id'))
op.drop_table('expense_payments')
with op.batch_alter_table('deals', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_deals_id'))
op.drop_table('deals')
with op.batch_alter_table('waste_log', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_waste_log_id'))
op.drop_table('waste_log')
with op.batch_alter_table('waiter_shifts', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_waiter_shifts_id'))
op.drop_table('waiter_shifts')
with op.batch_alter_table('tabs', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_tabs_id'))
op.drop_table('tabs')
with op.batch_alter_table('table_flag_assignments', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_table_flag_assignments_id'))
op.drop_table('table_flag_assignments')
with op.batch_alter_table('staff_message_acks', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_staff_message_acks_id'))
op.drop_table('staff_message_acks')
with op.batch_alter_table('reservations', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_reservations_id'))
op.drop_table('reservations')
with op.batch_alter_table('product_quick_options', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_product_quick_options_id'))
op.drop_table('product_quick_options')
op.drop_table('product_prep_zones')
with op.batch_alter_table('product_modifier_groups', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_product_modifier_groups_id'))
op.drop_table('product_modifier_groups')
with op.batch_alter_table('price_modifiers', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_price_modifiers_id'))
op.drop_table('price_modifiers')
op.drop_table('prep_zone_printers')
with op.batch_alter_table('orders', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_orders_id'))
op.drop_table('orders')
with op.batch_alter_table('expenses', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_expenses_id'))
op.drop_table('expenses')
with op.batch_alter_table('conversation_participants', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_conversation_participants_id'))
op.drop_table('conversation_participants')
with op.batch_alter_table('chat_messages', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_chat_messages_id'))
op.drop_table('chat_messages')
with op.batch_alter_table('waiter_zones', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_waiter_zones_id'))
op.drop_table('waiter_zones')
with op.batch_alter_table('waiter_discount_settings', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_waiter_discount_settings_id'))
op.drop_table('waiter_discount_settings')
with op.batch_alter_table('tables', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_tables_id'))
op.drop_table('tables')
with op.batch_alter_table('staff_messages', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_staff_messages_id'))
op.drop_table('staff_messages')
with op.batch_alter_table('site_todos', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_site_todos_id'))
op.drop_table('site_todos')
with op.batch_alter_table('site_notes', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_site_notes_id'))
op.drop_table('site_notes')
with op.batch_alter_table('scheduled_shifts', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_scheduled_shifts_id'))
op.drop_table('scheduled_shifts')
with op.batch_alter_table('recovery_codes', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_recovery_codes_user_id'))
batch_op.drop_index(batch_op.f('ix_recovery_codes_id'))
op.drop_table('recovery_codes')
with op.batch_alter_table('products', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_products_id'))
op.drop_table('products')
with op.batch_alter_table('price_groups', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_price_groups_id'))
op.drop_table('price_groups')
with op.batch_alter_table('prep_zones', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_prep_zones_id'))
op.drop_table('prep_zones')
op.drop_table('pos_settings')
with op.batch_alter_table('customers', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_customers_id'))
op.drop_table('customers')
with op.batch_alter_table('conversations', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_conversations_id'))
op.drop_table('conversations')
with op.batch_alter_table('business_days', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_business_days_id'))
op.drop_table('business_days')
with op.batch_alter_table('assistant_assignments', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_assistant_assignments_id'))
op.drop_table('assistant_assignments')
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_users_username'))
batch_op.drop_index(batch_op.f('ix_users_id'))
op.drop_table('users')
with op.batch_alter_table('table_groups', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_table_groups_id'))
op.drop_table('table_groups')
with op.batch_alter_table('table_flag_defs', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_table_flag_defs_id'))
op.drop_table('table_flag_defs')
with op.batch_alter_table('sync_events', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_sync_events_created_at'))
op.drop_table('sync_events')
with op.batch_alter_table('quick_message_templates', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_quick_message_templates_id'))
op.drop_table('quick_message_templates')
with op.batch_alter_table('printers', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_printers_id'))
op.drop_table('printers')
with op.batch_alter_table('contacts', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_contacts_id'))
op.drop_table('contacts')
with op.batch_alter_table('categories', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_categories_id'))
op.drop_table('categories')
# ### end Alembic commands ###