CREATE TABLE IF NOT EXISTS "migrations" ("id" integer primary key autoincrement not null, "migration" varchar not null, "batch" integer not null);
CREATE TABLE IF NOT EXISTS "users" ("id" integer primary key autoincrement not null, "name" varchar not null, "email" varchar not null, "email_verified_at" datetime, "password" varchar not null, "remember_token" varchar, "created_at" datetime, "updated_at" datetime, "profile_photo_path" varchar);
CREATE UNIQUE INDEX "users_email_unique" on "users" ("email");
CREATE TABLE IF NOT EXISTS "password_reset_tokens" ("email" varchar not null, "token" varchar not null, "created_at" datetime, primary key ("email"));
CREATE TABLE IF NOT EXISTS "failed_jobs" ("id" integer primary key autoincrement not null, "uuid" varchar not null, "connection" text not null, "queue" text not null, "payload" text not null, "exception" text not null, "failed_at" datetime not null default CURRENT_TIMESTAMP);
CREATE UNIQUE INDEX "failed_jobs_uuid_unique" on "failed_jobs" ("uuid");
CREATE TABLE IF NOT EXISTS "personal_access_tokens" ("id" integer primary key autoincrement not null, "tokenable_type" varchar not null, "tokenable_id" integer not null, "name" varchar not null, "token" varchar not null, "abilities" text, "last_used_at" datetime, "expires_at" datetime, "created_at" datetime, "updated_at" datetime);
CREATE INDEX "personal_access_tokens_tokenable_type_tokenable_id_index" on "personal_access_tokens" ("tokenable_type", "tokenable_id");
CREATE UNIQUE INDEX "personal_access_tokens_token_unique" on "personal_access_tokens" ("token");
CREATE TABLE IF NOT EXISTS "document_categories" ("id" integer primary key autoincrement not null, "name" varchar not null, "slug" varchar not null, "description" text, "icon" varchar, "sort_order" integer not null default '0', "default_access_level" varchar check ("default_access_level" in ('public', 'members', 'admin', 'board')) not null default 'members', "created_at" datetime, "updated_at" datetime);
CREATE UNIQUE INDEX "document_categories_slug_unique" on "document_categories" ("slug");
CREATE TABLE IF NOT EXISTS "documents" ("id" integer primary key autoincrement not null, "document_category_id" integer not null, "title" varchar not null, "document_number" varchar, "description" text, "public_uuid" varchar not null, "access_level" varchar check ("access_level" in ('public', 'members', 'admin', 'board')) not null default 'members', "current_version_id" integer, "status" varchar check ("status" in ('active', 'archived')) not null default 'active', "archived_at" datetime, "created_by_user_id" integer not null, "last_updated_by_user_id" integer, "view_count" integer not null default '0', "download_count" integer not null default '0', "version_count" integer not null default '0', "created_at" datetime, "updated_at" datetime, "deleted_at" datetime, "expires_at" date, "auto_archive_on_expiry" tinyint(1) not null default '0', "expiry_notice" text, foreign key("document_category_id") references "document_categories"("id") on delete cascade, foreign key("current_version_id") references "document_versions"("id") on delete set null, foreign key("created_by_user_id") references "users"("id") on delete cascade, foreign key("last_updated_by_user_id") references "users"("id") on delete set null);
CREATE INDEX "documents_document_category_id_index" on "documents" ("document_category_id");
CREATE INDEX "documents_access_level_index" on "documents" ("access_level");
CREATE INDEX "documents_status_index" on "documents" ("status");
CREATE INDEX "documents_public_uuid_index" on "documents" ("public_uuid");
CREATE INDEX "documents_created_at_index" on "documents" ("created_at");
CREATE UNIQUE INDEX "documents_document_number_unique" on "documents" ("document_number");
CREATE UNIQUE INDEX "documents_public_uuid_unique" on "documents" ("public_uuid");
CREATE TABLE IF NOT EXISTS "document_versions" ("id" integer primary key autoincrement not null, "document_id" integer not null, "version_number" varchar not null, "version_notes" text, "is_current" tinyint(1) not null default '0', "file_path" varchar not null, "original_filename" varchar not null, "mime_type" varchar not null, "file_size" integer not null, "file_hash" varchar, "uploaded_by_user_id" integer not null, "uploaded_at" datetime not null, "created_at" datetime, "updated_at" datetime, foreign key("document_id") references "documents"("id") on delete cascade, foreign key("uploaded_by_user_id") references "users"("id") on delete cascade);
CREATE INDEX "document_versions_document_id_index" on "document_versions" ("document_id");
CREATE INDEX "document_versions_version_number_index" on "document_versions" ("version_number");
CREATE INDEX "document_versions_is_current_index" on "document_versions" ("is_current");
CREATE INDEX "document_versions_uploaded_at_index" on "document_versions" ("uploaded_at");
CREATE TABLE IF NOT EXISTS "document_access_logs" ("id" integer primary key autoincrement not null, "document_id" integer not null, "document_version_id" integer, "action" varchar check ("action" in ('view', 'download')) not null, "user_id" integer, "ip_address" varchar, "user_agent" text, "accessed_at" datetime not null, "created_at" datetime, "updated_at" datetime, foreign key("document_id") references "documents"("id") on delete cascade, foreign key("document_version_id") references "document_versions"("id") on delete set null, foreign key("user_id") references "users"("id") on delete set null);
CREATE INDEX "document_access_logs_document_id_index" on "document_access_logs" ("document_id");
CREATE INDEX "document_access_logs_user_id_index" on "document_access_logs" ("user_id");
CREATE INDEX "document_access_logs_action_index" on "document_access_logs" ("action");
CREATE INDEX "document_access_logs_accessed_at_index" on "document_access_logs" ("accessed_at");
CREATE TABLE IF NOT EXISTS "members" ("id" integer primary key autoincrement not null, "user_id" integer, "full_name" varchar not null, "email" varchar not null, "phone" varchar, "national_id_encrypted" varchar, "national_id_hash" varchar, "membership_started_at" date, "membership_expires_at" date, "created_at" datetime, "updated_at" datetime, "last_expiry_reminder_sent_at" datetime, "address_line_1" varchar, "address_line_2" varchar, "city" varchar, "postal_code" varchar, "emergency_contact_name" varchar, "emergency_contact_phone" varchar, "membership_status" varchar check ("membership_status" in ('pending', 'active', 'expired', 'suspended')) not null default 'pending', "membership_type" varchar check ("membership_type" in ('individual', 'sponsor', 'honorary_academic', 'regular', 'honorary', 'lifetime', 'student')) not null default 'individual', "disability_certificate_path" varchar, "disability_certificate_status" varchar, "disability_verified_by" integer, "disability_verified_at" datetime, "disability_rejection_reason" text, foreign key("user_id") references "users"("id") on delete set null);
CREATE INDEX "members_email_index" on "members" ("email");
CREATE INDEX "members_national_id_hash_index" on "members" ("national_id_hash");
CREATE TABLE IF NOT EXISTS "membership_payments" ("id" integer primary key autoincrement not null, "member_id" integer not null, "paid_at" date not null, "amount" numeric not null, "method" varchar, "reference" varchar, "created_at" datetime, "updated_at" datetime, "status" varchar check ("status" in ('pending', 'approved_cashier', 'approved_accountant', 'approved_chair', 'rejected')) not null default 'pending', "payment_method" varchar check ("payment_method" in ('bank_transfer', 'convenience_store', 'cash', 'credit_card')), "receipt_path" varchar, "submitted_by_user_id" integer, "verified_by_cashier_id" integer, "cashier_verified_at" datetime, "verified_by_accountant_id" integer, "accountant_verified_at" datetime, "verified_by_chair_id" integer, "chair_verified_at" datetime, "rejected_by_user_id" integer, "rejected_at" datetime, "rejection_reason" text, "notes" text, "fee_type" varchar not null default 'entrance_fee', "base_amount" numeric, "discount_amount" numeric not null default '0', "final_amount" numeric, "disability_discount" tinyint(1) not null default '0', foreign key("member_id") references "members"("id") on delete cascade);
CREATE TABLE IF NOT EXISTS "permissions" ("id" integer primary key autoincrement not null, "name" varchar not null, "guard_name" varchar not null, "created_at" datetime, "updated_at" datetime);
CREATE UNIQUE INDEX "permissions_name_guard_name_unique" on "permissions" ("name", "guard_name");
CREATE TABLE IF NOT EXISTS "roles" ("id" integer primary key autoincrement not null, "name" varchar not null, "guard_name" varchar not null, "created_at" datetime, "updated_at" datetime, "description" varchar);
CREATE UNIQUE INDEX "roles_name_guard_name_unique" on "roles" ("name", "guard_name");
CREATE TABLE IF NOT EXISTS "model_has_permissions" ("permission_id" integer not null, "model_type" varchar not null, "model_id" integer not null, foreign key("permission_id") references "permissions"("id") on delete cascade, primary key ("permission_id", "model_id", "model_type"));
CREATE INDEX "model_has_permissions_model_id_model_type_index" on "model_has_permissions" ("model_id", "model_type");
CREATE TABLE IF NOT EXISTS "model_has_roles" ("role_id" integer not null, "model_type" varchar not null, "model_id" integer not null, foreign key("role_id") references "roles"("id") on delete cascade, primary key ("role_id", "model_id", "model_type"));
CREATE INDEX "model_has_roles_model_id_model_type_index" on "model_has_roles" ("model_id", "model_type");
CREATE TABLE IF NOT EXISTS "role_has_permissions" ("permission_id" integer not null, "role_id" integer not null, foreign key("permission_id") references "permissions"("id") on delete cascade, foreign key("role_id") references "roles"("id") on delete cascade, primary key ("permission_id", "role_id"));
CREATE TABLE IF NOT EXISTS "audit_logs" ("id" integer primary key autoincrement not null, "user_id" integer, "action" varchar not null, "auditable_type" varchar, "auditable_id" integer, "metadata" text, "created_at" datetime, "updated_at" datetime, "description" text, "ip_address" varchar, foreign key("user_id") references "users"("id") on delete set null);
CREATE TABLE IF NOT EXISTS "finance_documents" ("id" integer primary key autoincrement not null, "member_id" integer, "submitted_by_user_id" integer, "title" varchar not null, "amount" numeric, "status" varchar not null default 'pending', "description" text, "submitted_at" datetime, "created_at" datetime, "updated_at" datetime, "attachment_path" varchar, "approved_by_cashier_id" integer, "cashier_approved_at" datetime, "approved_by_accountant_id" integer, "accountant_approved_at" datetime, "approved_by_chair_id" integer, "chair_approved_at" datetime, "rejected_by_user_id" integer, "rejected_at" datetime, "rejection_reason" text, "submitted_by_id" integer, "amount_tier" varchar check ("amount_tier" in ('small', 'medium', 'large')), "chart_of_account_id" integer, "budget_item_id" integer, "requires_board_meeting" tinyint(1) not null default '0', "board_meeting_date" date, "board_meeting_decision" text, "approved_by_board_meeting_id" integer, "board_meeting_approved_at" datetime, "payment_order_created_by_accountant_id" integer, "payment_order_created_at" datetime, "payment_method" varchar check ("payment_method" in ('bank_transfer', 'check', 'cash')), "payee_name" varchar, "payee_bank_code" varchar, "payee_account_number" varchar, "payee_bank_name" varchar, "payment_notes" text, "payment_verified_by_cashier_id" integer, "payment_verified_at" datetime, "payment_verification_notes" text, "payment_executed_by_cashier_id" integer, "payment_executed_at" datetime, "payment_transaction_id" varchar, "payment_receipt_path" varchar, "actual_payment_amount" numeric, "cashier_ledger_entry_id" integer, "cashier_recorded_at" datetime, "accounting_transaction_id" integer, "accountant_recorded_at" datetime, "bank_reconciliation_id" integer, "reconciliation_status" varchar check ("reconciliation_status" in ('pending', 'matched', 'discrepancy', 'resolved')) not null default 'pending', "reconciliation_notes" text, "reconciled_at" datetime, "reconciled_by_user_id" integer, "approved_by_secretary_id" integer, "secretary_approved_at" datetime, "disbursement_status" varchar, "requester_confirmed_at" datetime, "requester_confirmed_by_id" integer, "cashier_confirmed_at" datetime, "cashier_confirmed_by_id" integer, "recording_status" varchar, "accountant_recorded_by_id" integer, foreign key("member_id") references "members"("id") on delete set null, foreign key("submitted_by_user_id") references "users"("id") on delete set null);
CREATE TABLE IF NOT EXISTS "chart_of_accounts" ("id" integer primary key autoincrement not null, "account_code" varchar not null, "account_name_zh" varchar not null, "account_name_en" varchar, "account_type" varchar check ("account_type" in ('asset', 'liability', 'net_asset', 'income', 'expense')) not null, "category" varchar, "parent_account_id" integer, "is_active" tinyint(1) not null default '1', "display_order" integer not null default '0', "description" text, "created_at" datetime, "updated_at" datetime, foreign key("parent_account_id") references "chart_of_accounts"("id") on delete set null);
CREATE INDEX "chart_of_accounts_account_type_index" on "chart_of_accounts" ("account_type");
CREATE INDEX "chart_of_accounts_is_active_index" on "chart_of_accounts" ("is_active");
CREATE UNIQUE INDEX "chart_of_accounts_account_code_unique" on "chart_of_accounts" ("account_code");
CREATE TABLE IF NOT EXISTS "budget_items" ("id" integer primary key autoincrement not null, "budget_id" integer not null, "chart_of_account_id" integer not null, "budgeted_amount" numeric not null default '0', "actual_amount" numeric not null default '0', "notes" text, "created_at" datetime, "updated_at" datetime, foreign key("budget_id") references "budgets"("id") on delete cascade, foreign key("chart_of_account_id") references "chart_of_accounts"("id") on delete cascade);
CREATE INDEX "budget_items_budget_id_chart_of_account_id_index" on "budget_items" ("budget_id", "chart_of_account_id");
CREATE TABLE IF NOT EXISTS "budgets" ("id" integer primary key autoincrement not null, "fiscal_year" integer not null, "name" varchar not null, "period_type" varchar check ("period_type" in ('annual', 'quarterly', 'monthly')) not null default 'annual', "period_start" date not null, "period_end" date not null, "status" varchar check ("status" in ('draft', 'submitted', 'approved', 'active', 'closed')) not null default 'draft', "created_by_user_id" integer not null, "approved_by_user_id" integer, "approved_at" datetime, "notes" text, "created_at" datetime, "updated_at" datetime, foreign key("created_by_user_id") references "users"("id") on delete cascade, foreign key("approved_by_user_id") references "users"("id") on delete set null);
CREATE INDEX "budgets_fiscal_year_index" on "budgets" ("fiscal_year");
CREATE INDEX "budgets_status_index" on "budgets" ("status");
CREATE TABLE IF NOT EXISTS "transactions" ("id" integer primary key autoincrement not null, "budget_item_id" integer, "chart_of_account_id" integer not null, "transaction_date" date not null, "amount" numeric not null, "transaction_type" varchar check ("transaction_type" in ('income', 'expense')) not null, "description" varchar not null, "reference_number" varchar, "finance_document_id" integer, "membership_payment_id" integer, "created_by_user_id" integer not null, "notes" text, "created_at" datetime, "updated_at" datetime, foreign key("budget_item_id") references "budget_items"("id") on delete set null, foreign key("chart_of_account_id") references "chart_of_accounts"("id") on delete cascade, foreign key("finance_document_id") references "finance_documents"("id") on delete set null, foreign key("membership_payment_id") references "membership_payments"("id") on delete set null, foreign key("created_by_user_id") references "users"("id") on delete cascade);
CREATE INDEX "transactions_transaction_date_index" on "transactions" ("transaction_date");
CREATE INDEX "transactions_transaction_type_index" on "transactions" ("transaction_type");
CREATE INDEX "transactions_budget_item_id_transaction_date_index" on "transactions" ("budget_item_id", "transaction_date");
CREATE TABLE IF NOT EXISTS "financial_reports" ("id" integer primary key autoincrement not null, "report_type" varchar check ("report_type" in ('revenue_expenditure', 'balance_sheet', 'property_inventory', 'internal_management')) not null, "fiscal_year" integer not null, "period_start" date not null, "period_end" date not null, "status" varchar check ("status" in ('draft', 'finalized', 'approved', 'submitted')) not null default 'draft', "budget_id" integer, "generated_by_user_id" integer not null, "approved_by_user_id" integer, "approved_at" datetime, "file_path" varchar, "notes" text, "created_at" datetime, "updated_at" datetime, foreign key("budget_id") references "budgets"("id") on delete set null, foreign key("generated_by_user_id") references "users"("id") on delete cascade, foreign key("approved_by_user_id") references "users"("id") on delete set null);
CREATE INDEX "financial_reports_report_type_fiscal_year_index" on "financial_reports" ("report_type", "fiscal_year");
CREATE INDEX "financial_reports_status_index" on "financial_reports" ("status");
CREATE TABLE IF NOT EXISTS "issues" ("id" integer primary key autoincrement not null, "issue_number" varchar not null, "title" varchar not null, "description" text, "issue_type" varchar check ("issue_type" in ('work_item', 'project_task', 'maintenance', 'member_request')) not null default 'work_item', "status" varchar check ("status" in ('new', 'assigned', 'in_progress', 'review', 'closed')) not null default 'new', "priority" varchar check ("priority" in ('low', 'medium', 'high', 'urgent')) not null default 'medium', "created_by_user_id" integer not null, "assigned_to_user_id" integer, "reviewer_id" integer, "member_id" integer, "parent_issue_id" integer, "due_date" date, "closed_at" datetime, "estimated_hours" numeric, "actual_hours" numeric not null default '0', "created_at" datetime, "updated_at" datetime, "deleted_at" datetime, foreign key("created_by_user_id") references "users"("id") on delete cascade, foreign key("assigned_to_user_id") references "users"("id") on delete set null, foreign key("reviewer_id") references "users"("id") on delete set null, foreign key("member_id") references "members"("id") on delete set null, foreign key("parent_issue_id") references "issues"("id") on delete set null);
CREATE INDEX "issues_issue_type_index" on "issues" ("issue_type");
CREATE INDEX "issues_status_index" on "issues" ("status");
CREATE INDEX "issues_priority_index" on "issues" ("priority");
CREATE INDEX "issues_assigned_to_user_id_index" on "issues" ("assigned_to_user_id");
CREATE INDEX "issues_created_by_user_id_index" on "issues" ("created_by_user_id");
CREATE INDEX "issues_due_date_index" on "issues" ("due_date");
CREATE UNIQUE INDEX "issues_issue_number_unique" on "issues" ("issue_number");
CREATE TABLE IF NOT EXISTS "issue_comments" ("id" integer primary key autoincrement not null, "issue_id" integer not null, "user_id" integer not null, "comment_text" text not null, "is_internal" tinyint(1) not null default '0', "created_at" datetime, "updated_at" datetime, foreign key("issue_id") references "issues"("id") on delete cascade, foreign key("user_id") references "users"("id") on delete cascade);
CREATE INDEX "issue_comments_issue_id_index" on "issue_comments" ("issue_id");
CREATE INDEX "issue_comments_user_id_index" on "issue_comments" ("user_id");
CREATE TABLE IF NOT EXISTS "issue_attachments" ("id" integer primary key autoincrement not null, "issue_id" integer not null, "user_id" integer not null, "file_name" varchar not null, "file_path" varchar not null, "file_size" integer not null, "mime_type" varchar not null, "created_at" datetime, "updated_at" datetime, foreign key("issue_id") references "issues"("id") on delete cascade, foreign key("user_id") references "users"("id") on delete cascade);
CREATE INDEX "issue_attachments_issue_id_index" on "issue_attachments" ("issue_id");
CREATE TABLE IF NOT EXISTS "custom_field_values" ("id" integer primary key autoincrement not null, "custom_field_id" integer not null, "customizable_type" varchar not null, "customizable_id" integer not null, "value" text not null, "created_at" datetime, "updated_at" datetime, foreign key("custom_field_id") references "custom_fields"("id") on delete cascade);
CREATE INDEX "custom_field_values_customizable_type_customizable_id_index" on "custom_field_values" ("customizable_type", "customizable_id");
CREATE INDEX "custom_field_values_custom_field_id_index" on "custom_field_values" ("custom_field_id");
CREATE TABLE IF NOT EXISTS "custom_fields" ("id" integer primary key autoincrement not null, "name" varchar not null, "field_type" varchar check ("field_type" in ('text', 'number', 'date', 'select')) not null, "options" text, "applies_to_issue_types" text not null, "is_required" tinyint(1) not null default '0', "display_order" integer not null default '0', "created_at" datetime, "updated_at" datetime);
CREATE UNIQUE INDEX "custom_fields_name_unique" on "custom_fields" ("name");
CREATE TABLE IF NOT EXISTS "issue_label_pivot" ("issue_id" integer not null, "issue_label_id" integer not null, "created_at" datetime, "updated_at" datetime, foreign key("issue_id") references "issues"("id") on delete cascade, foreign key("issue_label_id") references "issue_labels"("id") on delete cascade, primary key ("issue_id", "issue_label_id"));
CREATE TABLE IF NOT EXISTS "issue_labels" ("id" integer primary key autoincrement not null, "name" varchar not null, "color" varchar not null default '#6B7280', "description" text, "created_at" datetime, "updated_at" datetime);
CREATE UNIQUE INDEX "issue_labels_name_unique" on "issue_labels" ("name");
CREATE TABLE IF NOT EXISTS "issue_relationships" ("id" integer primary key autoincrement not null, "issue_id" integer not null, "related_issue_id" integer not null, "relationship_type" varchar check ("relationship_type" in ('blocks', 'blocked_by', 'related_to', 'duplicate_of')) not null, "created_at" datetime, "updated_at" datetime, foreign key("issue_id") references "issues"("id") on delete cascade, foreign key("related_issue_id") references "issues"("id") on delete cascade);
CREATE INDEX "issue_relationships_issue_id_index" on "issue_relationships" ("issue_id");
CREATE INDEX "issue_relationships_related_issue_id_index" on "issue_relationships" ("related_issue_id");
CREATE TABLE IF NOT EXISTS "issue_time_logs" ("id" integer primary key autoincrement not null, "issue_id" integer not null, "user_id" integer not null, "hours" numeric not null, "description" text, "logged_at" datetime not null, "created_at" datetime, "updated_at" datetime, foreign key("issue_id") references "issues"("id") on delete cascade, foreign key("user_id") references "users"("id") on delete cascade);
CREATE INDEX "issue_time_logs_issue_id_index" on "issue_time_logs" ("issue_id");
CREATE INDEX "issue_time_logs_user_id_index" on "issue_time_logs" ("user_id");
CREATE INDEX "issue_time_logs_logged_at_index" on "issue_time_logs" ("logged_at");
CREATE TABLE IF NOT EXISTS "issue_watchers" ("issue_id" integer not null, "user_id" integer not null, "created_at" datetime, "updated_at" datetime, foreign key("issue_id") references "issues"("id") on delete cascade, foreign key("user_id") references "users"("id") on delete cascade, primary key ("issue_id", "user_id"));
CREATE TABLE IF NOT EXISTS "document_tags" ("id" integer primary key autoincrement not null, "name" varchar not null, "slug" varchar not null, "color" varchar not null default '#6366f1', "description" text, "created_at" datetime, "updated_at" datetime);
CREATE UNIQUE INDEX "document_tags_slug_unique" on "document_tags" ("slug");
CREATE TABLE IF NOT EXISTS "document_document_tag" ("id" integer primary key autoincrement not null, "document_id" integer not null, "document_tag_id" integer not null, "created_at" datetime, "updated_at" datetime, foreign key("document_id") references "documents"("id") on delete cascade, foreign key("document_tag_id") references "document_tags"("id") on delete cascade);
CREATE UNIQUE INDEX "document_document_tag_document_id_document_tag_id_unique" on "document_document_tag" ("document_id", "document_tag_id");
CREATE TABLE IF NOT EXISTS "system_settings" ("id" integer primary key autoincrement not null, "key" varchar not null, "value" text, "type" varchar check ("type" in ('string', 'integer', 'boolean', 'json', 'array')) not null default 'string', "group" varchar, "description" text, "created_at" datetime, "updated_at" datetime);
CREATE UNIQUE INDEX "system_settings_key_unique" on "system_settings" ("key");
CREATE INDEX "system_settings_group_index" on "system_settings" ("group");
CREATE TABLE IF NOT EXISTS "payment_orders" ("id" integer primary key autoincrement not null, "finance_document_id" integer not null, "payee_name" varchar not null, "payee_bank_code" varchar, "payee_account_number" varchar, "payee_bank_name" varchar, "payment_amount" numeric not null, "payment_method" varchar check ("payment_method" in ('bank_transfer', 'check', 'cash')) not null, "created_by_accountant_id" integer not null, "payment_order_number" varchar not null, "notes" text, "verified_by_cashier_id" integer, "verified_at" datetime, "verification_status" varchar check ("verification_status" in ('pending', 'approved', 'rejected')) not null default 'pending', "verification_notes" text, "executed_by_cashier_id" integer, "executed_at" datetime, "execution_status" varchar check ("execution_status" in ('pending', 'completed', 'failed')) not null default 'pending', "transaction_reference" varchar, "payment_receipt_path" varchar, "status" varchar check ("status" in ('draft', 'pending_verification', 'verified', 'executed', 'cancelled')) not null default 'draft', "created_at" datetime, "updated_at" datetime, foreign key("finance_document_id") references "finance_documents"("id") on delete cascade, foreign key("created_by_accountant_id") references "users"("id") on delete cascade, foreign key("verified_by_cashier_id") references "users"("id") on delete set null, foreign key("executed_by_cashier_id") references "users"("id") on delete set null);
CREATE INDEX "payment_orders_finance_document_id_index" on "payment_orders" ("finance_document_id");
CREATE INDEX "payment_orders_status_index" on "payment_orders" ("status");
CREATE INDEX "payment_orders_verification_status_index" on "payment_orders" ("verification_status");
CREATE INDEX "payment_orders_execution_status_index" on "payment_orders" ("execution_status");
CREATE UNIQUE INDEX "payment_orders_payment_order_number_unique" on "payment_orders" ("payment_order_number");
CREATE TABLE IF NOT EXISTS "cashier_ledger_entries" ("id" integer primary key autoincrement not null, "finance_document_id" integer, "entry_date" date not null, "entry_type" varchar check ("entry_type" in ('receipt', 'payment')) not null, "payment_method" varchar check ("payment_method" in ('bank_transfer', 'check', 'cash')) not null, "bank_account" varchar, "amount" numeric not null, "balance_before" numeric not null, "balance_after" numeric not null, "receipt_number" varchar, "transaction_reference" varchar, "recorded_by_cashier_id" integer not null, "recorded_at" datetime not null default CURRENT_TIMESTAMP, "notes" text, "created_at" datetime, "updated_at" datetime, foreign key("finance_document_id") references "finance_documents"("id") on delete cascade, foreign key("recorded_by_cashier_id") references "users"("id") on delete cascade);
CREATE INDEX "cashier_ledger_entries_finance_document_id_index" on "cashier_ledger_entries" ("finance_document_id");
CREATE INDEX "cashier_ledger_entries_entry_date_index" on "cashier_ledger_entries" ("entry_date");
CREATE INDEX "cashier_ledger_entries_entry_type_index" on "cashier_ledger_entries" ("entry_type");
CREATE INDEX "cashier_ledger_entries_recorded_by_cashier_id_index" on "cashier_ledger_entries" ("recorded_by_cashier_id");
CREATE TABLE IF NOT EXISTS "bank_reconciliations" ("id" integer primary key autoincrement not null, "reconciliation_month" date not null, "bank_statement_balance" numeric not null, "bank_statement_date" date not null, "bank_statement_file_path" varchar, "system_book_balance" numeric not null, "outstanding_checks" text, "deposits_in_transit" text, "bank_charges" text, "adjusted_balance" numeric not null, "discrepancy_amount" numeric not null default '0', "reconciliation_status" varchar check ("reconciliation_status" in ('pending', 'completed', 'discrepancy')) not null default 'pending', "prepared_by_cashier_id" integer not null, "reviewed_by_accountant_id" integer, "approved_by_manager_id" integer, "prepared_at" datetime not null default CURRENT_TIMESTAMP, "reviewed_at" datetime, "approved_at" datetime, "notes" text, "created_at" datetime, "updated_at" datetime, foreign key("prepared_by_cashier_id") references "users"("id") on delete cascade, foreign key("reviewed_by_accountant_id") references "users"("id") on delete set null, foreign key("approved_by_manager_id") references "users"("id") on delete set null);
CREATE INDEX "bank_reconciliations_reconciliation_month_index" on "bank_reconciliations" ("reconciliation_month");
CREATE INDEX "bank_reconciliations_reconciliation_status_index" on "bank_reconciliations" ("reconciliation_status");
CREATE TABLE IF NOT EXISTS "announcements" ("id" integer primary key autoincrement not null, "title" varchar not null, "content" text not null, "status" varchar check ("status" in ('draft', 'published', 'archived')) not null default 'draft', "is_pinned" tinyint(1) not null default '0', "display_order" integer not null default '0', "access_level" varchar check ("access_level" in ('public', 'members', 'board', 'admin')) not null default 'members', "published_at" datetime, "expires_at" datetime, "archived_at" datetime, "view_count" integer not null default '0', "created_by_user_id" integer not null, "last_updated_by_user_id" integer, "created_at" datetime, "updated_at" datetime, "deleted_at" datetime, foreign key("created_by_user_id") references "users"("id") on delete cascade, foreign key("last_updated_by_user_id") references "users"("id") on delete set null);
CREATE INDEX "announcements_status_index" on "announcements" ("status");
CREATE INDEX "announcements_access_level_index" on "announcements" ("access_level");
CREATE INDEX "announcements_published_at_index" on "announcements" ("published_at");
CREATE INDEX "announcements_expires_at_index" on "announcements" ("expires_at");
CREATE INDEX "announcements_is_pinned_display_order_index" on "announcements" ("is_pinned", "display_order");
CREATE TABLE IF NOT EXISTS "accounting_entries" ("id" integer primary key autoincrement not null, "finance_document_id" integer not null, "chart_of_account_id" integer not null, "entry_type" varchar check ("entry_type" in ('debit', 'credit')) not null, "amount" numeric not null, "entry_date" date not null, "description" text, "created_at" datetime, "updated_at" datetime, "income_id" integer, foreign key("finance_document_id") references "finance_documents"("id") on delete cascade, foreign key("chart_of_account_id") references "chart_of_accounts"("id"));
CREATE INDEX "accounting_entries_finance_document_id_entry_type_index" on "accounting_entries" ("finance_document_id", "entry_type");
CREATE INDEX "accounting_entries_chart_of_account_id_entry_date_index" on "accounting_entries" ("chart_of_account_id", "entry_date");
CREATE TABLE IF NOT EXISTS "board_meetings" ("id" integer primary key autoincrement not null, "meeting_date" date not null, "title" varchar not null, "notes" text, "status" varchar check ("status" in ('scheduled', 'completed', 'cancelled')) not null default 'scheduled', "created_at" datetime, "updated_at" datetime);
CREATE TABLE IF NOT EXISTS "incomes" ("id" integer primary key autoincrement not null, "income_number" varchar not null, "title" varchar not null, "description" text, "income_date" date not null, "amount" numeric not null, "income_type" varchar not null, "chart_of_account_id" integer not null, "payment_method" varchar not null, "bank_account" varchar, "payer_name" varchar, "receipt_number" varchar, "transaction_reference" varchar, "attachment_path" varchar, "member_id" integer, "status" varchar not null default 'pending', "recorded_by_cashier_id" integer not null, "recorded_at" datetime not null, "confirmed_by_accountant_id" integer, "confirmed_at" datetime, "cashier_ledger_entry_id" integer, "notes" text, "created_at" datetime, "updated_at" datetime, foreign key("chart_of_account_id") references "chart_of_accounts"("id"), foreign key("member_id") references "members"("id") on delete set null, foreign key("recorded_by_cashier_id") references "users"("id"), foreign key("confirmed_by_accountant_id") references "users"("id"), foreign key("cashier_ledger_entry_id") references "cashier_ledger_entries"("id") on delete set null);
CREATE INDEX "incomes_income_date_index" on "incomes" ("income_date");
CREATE INDEX "incomes_income_type_index" on "incomes" ("income_type");
CREATE INDEX "incomes_status_index" on "incomes" ("status");
CREATE INDEX "incomes_member_id_income_type_index" on "incomes" ("member_id", "income_type");
CREATE UNIQUE INDEX "incomes_income_number_unique" on "incomes" ("income_number");
INSERT INTO migrations VALUES(1,'2014_10_12_000000_create_users_table',1);
INSERT INTO migrations VALUES(2,'2014_10_12_100000_create_password_reset_tokens_table',1);
INSERT INTO migrations VALUES(3,'2019_08_19_000000_create_failed_jobs_table',1);
INSERT INTO migrations VALUES(4,'2019_12_14_000001_create_personal_access_tokens_table',1);
INSERT INTO migrations VALUES(5,'2024_01_20_100000_create_document_categories_table',1);
INSERT INTO migrations VALUES(6,'2024_01_20_100001_create_documents_table',1);
INSERT INTO migrations VALUES(7,'2024_01_20_100002_create_document_versions_table',1);
INSERT INTO migrations VALUES(8,'2024_01_20_100003_create_document_access_logs_table',1);
INSERT INTO migrations VALUES(9,'2025_01_01_000000_create_members_table',1);
INSERT INTO migrations VALUES(10,'2025_01_01_000100_create_membership_payments_table',1);
INSERT INTO migrations VALUES(11,'2025_01_01_000200_add_is_admin_to_users_table',1);
INSERT INTO migrations VALUES(12,'2025_11_18_083552_create_permission_tables',1);
INSERT INTO migrations VALUES(13,'2025_11_18_090000_migrate_is_admin_to_roles',1);
INSERT INTO migrations VALUES(14,'2025_11_18_091000_add_last_expiry_reminder_to_members_table',1);
INSERT INTO migrations VALUES(15,'2025_11_18_092000_create_audit_logs_table',1);
INSERT INTO migrations VALUES(16,'2025_11_18_093000_create_finance_documents_table',1);
INSERT INTO migrations VALUES(17,'2025_11_18_094000_add_address_fields_to_members_table',1);
INSERT INTO migrations VALUES(18,'2025_11_18_100000_add_description_to_roles_table',1);
INSERT INTO migrations VALUES(19,'2025_11_18_101000_add_emergency_contact_to_members_table',1);
INSERT INTO migrations VALUES(20,'2025_11_18_102000_add_profile_photo_to_users_table',1);
INSERT INTO migrations VALUES(21,'2025_11_19_125201_add_approval_fields_to_finance_documents_table',1);
INSERT INTO migrations VALUES(22,'2025_11_19_133704_create_chart_of_accounts_table',1);
INSERT INTO migrations VALUES(23,'2025_11_19_133732_create_budget_items_table',1);
INSERT INTO migrations VALUES(24,'2025_11_19_133732_create_budgets_table',1);
INSERT INTO migrations VALUES(25,'2025_11_19_133802_create_transactions_table',1);
INSERT INTO migrations VALUES(26,'2025_11_19_133828_create_financial_reports_table',1);
INSERT INTO migrations VALUES(27,'2025_11_19_144027_create_issues_table',1);
INSERT INTO migrations VALUES(28,'2025_11_19_144059_create_issue_comments_table',1);
INSERT INTO migrations VALUES(29,'2025_11_19_144129_create_issue_attachments_table',1);
INSERT INTO migrations VALUES(30,'2025_11_19_144130_create_custom_field_values_table',1);
INSERT INTO migrations VALUES(31,'2025_11_19_144130_create_custom_fields_table',1);
INSERT INTO migrations VALUES(32,'2025_11_19_144130_create_issue_label_pivot_table',1);
INSERT INTO migrations VALUES(33,'2025_11_19_144130_create_issue_labels_table',1);
INSERT INTO migrations VALUES(34,'2025_11_19_144130_create_issue_relationships_table',1);
INSERT INTO migrations VALUES(35,'2025_11_19_144130_create_issue_time_logs_table',1);
INSERT INTO migrations VALUES(36,'2025_11_19_144130_create_issue_watchers_table',1);
INSERT INTO migrations VALUES(37,'2025_11_19_155725_enhance_membership_payments_table_for_verification',1);
INSERT INTO migrations VALUES(38,'2025_11_19_155807_add_membership_status_to_members_table',1);
INSERT INTO migrations VALUES(39,'2025_11_20_080537_remove_unique_constraint_from_document_versions',1);
INSERT INTO migrations VALUES(40,'2025_11_20_084936_create_document_tags_table',1);
INSERT INTO migrations VALUES(41,'2025_11_20_085035_add_expiration_to_documents_table',1);
INSERT INTO migrations VALUES(42,'2025_11_20_095222_create_system_settings_table',1);
INSERT INTO migrations VALUES(43,'2025_11_20_125121_add_payment_stage_fields_to_finance_documents_table',1);
INSERT INTO migrations VALUES(44,'2025_11_20_125246_create_payment_orders_table',1);
INSERT INTO migrations VALUES(45,'2025_11_20_125247_create_cashier_ledger_entries_table',1);
INSERT INTO migrations VALUES(46,'2025_11_20_125249_create_bank_reconciliations_table',1);
INSERT INTO migrations VALUES(47,'2025_11_28_182012_remove_is_admin_from_users_table',2);
INSERT INTO migrations VALUES(48,'2025_11_28_231917_create_cashier_ledger_entries_table',3);
INSERT INTO migrations VALUES(49,'2025_11_29_003312_create_announcements_table',4);
INSERT INTO migrations VALUES(50,'2025_11_29_010220_add_description_and_ip_address_to_audit_logs_table',5);
INSERT INTO migrations VALUES(51,'2025_11_30_153609_create_accounting_entries_table',6);
INSERT INTO migrations VALUES(52,'2025_11_30_163310_create_board_meetings_table',7);
INSERT INTO migrations VALUES(53,'2025_11_30_171203_add_new_workflow_fields_to_finance_documents',8);
INSERT INTO migrations VALUES(54,'2025_11_30_175637_remove_request_type_from_finance_documents',9);
INSERT INTO migrations VALUES(55,'2025_11_30_182639_create_incomes_table',10);
INSERT INTO migrations VALUES(56,'2025_11_30_212201_add_disability_fields_to_members_table',11);
INSERT INTO migrations VALUES(57,'2025_11_30_212227_add_fee_type_to_membership_payments_table',11);
INSERT INTO migrations VALUES(58,'2026_01_24_091609_add_secretary_approval_fields_to_finance_documents',12);
