using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace General_Ledger_Service.Migrations
{
///
public partial class InitialMySql : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "account_type",
columns: table => new
{
id = table.Column(type: "smallint", nullable: false),
name = table.Column(type: "varchar(50)", maxLength: 50, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
normal_balance = table.Column(type: "char(2)", maxLength: 2, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_account_type", x => x.id);
table.CheckConstraint("CK_account_type_normal_balance", "normal_balance IN ('DR','CR')");
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "audit_log",
columns: table => new
{
audit_log_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
category = table.Column(type: "int", nullable: false),
entity_name = table.Column(type: "varchar(50)", maxLength: 50, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
entity_id = table.Column(type: "varchar(50)", maxLength: 50, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
action = table.Column(type: "int", nullable: false),
description = table.Column(type: "text", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
performed_by = table.Column(type: "varchar(100)", maxLength: 100, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
occurred_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_audit_log", x => x.audit_log_id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "cost_center",
columns: table => new
{
cost_center_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
code = table.Column(type: "varchar(20)", maxLength: 20, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
name = table.Column(type: "varchar(150)", maxLength: 150, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
parent_cost_center_id = table.Column(type: "bigint", nullable: true),
is_active = table.Column(type: "tinyint(1)", nullable: false, defaultValue: true),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_cost_center", x => x.cost_center_id);
table.ForeignKey(
name: "f_k_cost_center_cost_center_parent_cost_center_id",
column: x => x.parent_cost_center_id,
principalTable: "cost_center",
principalColumn: "cost_center_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "currency",
columns: table => new
{
currency_code = table.Column(type: "char(3)", maxLength: 3, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
currency_name = table.Column(type: "varchar(50)", maxLength: 50, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
symbol = table.Column(type: "varchar(5)", maxLength: 5, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
decimal_places = table.Column(type: "smallint", nullable: false),
is_base_currency = table.Column(type: "tinyint(1)", nullable: false, defaultValue: false),
is_active = table.Column(type: "tinyint(1)", nullable: false, defaultValue: true),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_currency", x => x.currency_code);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "fiscal_year",
columns: table => new
{
fiscal_year_id = table.Column(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
year_name = table.Column(type: "varchar(20)", maxLength: 20, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
start_date = table.Column(type: "date", nullable: false),
end_date = table.Column(type: "date", nullable: false),
is_closed = table.Column(type: "tinyint(1)", nullable: false, defaultValue: false),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_fiscal_year", x => x.fiscal_year_id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "recurring_journal_template",
columns: table => new
{
template_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
template_name = table.Column(type: "varchar(150)", maxLength: 150, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
recurrence_pattern = table.Column(type: "int", nullable: false),
next_run_date = table.Column(type: "date", nullable: false),
end_date = table.Column(type: "date", nullable: true),
is_active = table.Column(type: "tinyint(1)", nullable: false, defaultValue: true),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_recurring_journal_template", x => x.template_id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "system_config",
columns: table => new
{
config_key = table.Column(type: "varchar(50)", maxLength: 50, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
config_value = table.Column(type: "varchar(255)", maxLength: 255, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
description = table.Column(type: "text", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
is_editable = table.Column(type: "tinyint(1)", nullable: false, defaultValue: true),
is_locked = table.Column(type: "tinyint(1)", nullable: false, defaultValue: false),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_system_config", x => x.config_key);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "tax_type",
columns: table => new
{
tax_type_id = table.Column(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
code = table.Column(type: "varchar(20)", maxLength: 20, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
name = table.Column(type: "varchar(100)", maxLength: 100, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_tax_type", x => x.tax_type_id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "accounts",
columns: table => new
{
account_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
account_code = table.Column(type: "varchar(20)", maxLength: 20, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
account_name = table.Column(type: "varchar(150)", maxLength: 150, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
parent_account_id = table.Column(type: "bigint", nullable: true),
account_type_id = table.Column(type: "smallint", nullable: false),
is_control_account = table.Column(type: "tinyint(1)", nullable: false, defaultValue: false),
is_postable = table.Column(type: "tinyint(1)", nullable: false, defaultValue: true),
currency_code = table.Column(type: "char(3)", maxLength: 3, nullable: false, defaultValue: "LKR")
.Annotation("MySql:CharSet", "utf8mb4"),
cash_flow_category = table.Column(type: "varchar(15)", maxLength: 15, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
income_statement_section = table.Column(type: "varchar(25)", maxLength: 25, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
balance_sheet_classification = table.Column(type: "varchar(25)", maxLength: 25, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
is_tax_deductible = table.Column(type: "tinyint(1)", nullable: false, defaultValue: true),
is_active = table.Column(type: "tinyint(1)", nullable: false, defaultValue: true),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_accounts", x => x.account_id);
table.ForeignKey(
name: "f_k_accounts_account_type_account_type_id",
column: x => x.account_type_id,
principalTable: "account_type",
principalColumn: "id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_accounts_accounts_parent_account_id",
column: x => x.parent_account_id,
principalTable: "accounts",
principalColumn: "account_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_accounts_currency_currency_code",
column: x => x.currency_code,
principalTable: "currency",
principalColumn: "currency_code",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "exchange_rate",
columns: table => new
{
rate_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
currency_code = table.Column(type: "char(3)", maxLength: 3, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
rate_date = table.Column(type: "date", nullable: false),
rate_to_base = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false),
rate_source = table.Column(type: "varchar(30)", maxLength: 30, nullable: false, defaultValue: "MANUAL")
.Annotation("MySql:CharSet", "utf8mb4"),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_exchange_rate", x => x.rate_id);
table.ForeignKey(
name: "f_k_exchange_rate_currency_currency_code",
column: x => x.currency_code,
principalTable: "currency",
principalColumn: "currency_code",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "accounting_period",
columns: table => new
{
period_id = table.Column(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
fiscal_year_id = table.Column(type: "int", nullable: false),
period_number = table.Column(type: "smallint", nullable: false),
start_date = table.Column(type: "date", nullable: false),
end_date = table.Column(type: "date", nullable: false),
status = table.Column(type: "int", nullable: false, defaultValue: 1),
lock_gl = table.Column(type: "tinyint(1)", nullable: false, defaultValue: false),
lock_reason = table.Column(type: "varchar(255)", maxLength: 255, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_accounting_period", x => x.period_id);
table.ForeignKey(
name: "f_k_accounting_period_fiscal_year_fiscal_year_id",
column: x => x.fiscal_year_id,
principalTable: "fiscal_year",
principalColumn: "fiscal_year_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "budget",
columns: table => new
{
budget_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
fiscal_year_id = table.Column(type: "int", nullable: false),
name = table.Column(type: "varchar(100)", maxLength: 100, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_budget", x => x.budget_id);
table.ForeignKey(
name: "f_k_budget_fiscal_year_fiscal_year_id",
column: x => x.fiscal_year_id,
principalTable: "fiscal_year",
principalColumn: "fiscal_year_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "bank_account",
columns: table => new
{
bank_account_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
account_name = table.Column(type: "varchar(150)", maxLength: 150, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
bank_name = table.Column(type: "varchar(150)", maxLength: 150, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
account_number = table.Column(type: "varchar(50)", maxLength: 50, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
gl_account_id = table.Column(type: "bigint", nullable: false),
currency_code = table.Column(type: "char(3)", maxLength: 3, nullable: false, defaultValue: "LKR")
.Annotation("MySql:CharSet", "utf8mb4"),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_bank_account", x => x.bank_account_id);
table.ForeignKey(
name: "f_k_bank_account_accounts_gl_account_id",
column: x => x.gl_account_id,
principalTable: "accounts",
principalColumn: "account_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_bank_account_currency_currency_code",
column: x => x.currency_code,
principalTable: "currency",
principalColumn: "currency_code",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "cash_account_type",
columns: table => new
{
cash_account_type_id = table.Column(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
name = table.Column(type: "varchar(100)", maxLength: 100, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
gl_account_id = table.Column(type: "bigint", nullable: true),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_cash_account_type", x => x.cash_account_type_id);
table.ForeignKey(
name: "f_k_cash_account_type_accounts_gl_account_id",
column: x => x.gl_account_id,
principalTable: "accounts",
principalColumn: "account_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "currency_rounding_rule",
columns: table => new
{
currency_code = table.Column(type: "char(3)", maxLength: 3, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
rounding_method = table.Column(type: "varchar(15)", maxLength: 15, nullable: false, defaultValue: "NEAREST")
.Annotation("MySql:CharSet", "utf8mb4"),
rounding_account_id = table.Column(type: "bigint", nullable: true),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_currency_rounding_rule", x => x.currency_code);
table.ForeignKey(
name: "f_k_currency_rounding_rule_accounts_rounding_account_id",
column: x => x.rounding_account_id,
principalTable: "accounts",
principalColumn: "account_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_currency_rounding_rule_currency_currency_code",
column: x => x.currency_code,
principalTable: "currency",
principalColumn: "currency_code",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "fixed_asset",
columns: table => new
{
asset_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
asset_code = table.Column(type: "varchar(30)", maxLength: 30, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
asset_name = table.Column(type: "varchar(150)", maxLength: 150, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
asset_account_id = table.Column(type: "bigint", nullable: false),
accum_depr_account_id = table.Column(type: "bigint", nullable: false),
depr_expense_account_id = table.Column(type: "bigint", nullable: false),
gain_loss_account_id = table.Column(type: "bigint", nullable: false),
acquisition_date = table.Column(type: "date", nullable: false),
acquisition_cost = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false),
residual_value = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false, defaultValue: 0m),
useful_life_months = table.Column(type: "int", nullable: false),
depreciation_method = table.Column(type: "int", nullable: false, defaultValue: 1),
depreciation_rate_percent = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: true),
status = table.Column(type: "int", nullable: false, defaultValue: 1),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_fixed_asset", x => x.asset_id);
table.ForeignKey(
name: "f_k_fixed_asset_accounts_accum_depr_account_id",
column: x => x.accum_depr_account_id,
principalTable: "accounts",
principalColumn: "account_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_fixed_asset_accounts_asset_account_id",
column: x => x.asset_account_id,
principalTable: "accounts",
principalColumn: "account_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_fixed_asset_accounts_depr_expense_account_id",
column: x => x.depr_expense_account_id,
principalTable: "accounts",
principalColumn: "account_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_fixed_asset_accounts_gain_loss_account_id",
column: x => x.gain_loss_account_id,
principalTable: "accounts",
principalColumn: "account_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "recurring_journal_template_line",
columns: table => new
{
line_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
template_id = table.Column(type: "bigint", nullable: false),
account_id = table.Column(type: "bigint", nullable: false),
debit_amount = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false, defaultValue: 0m),
credit_amount = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false, defaultValue: 0m),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_recurring_journal_template_line", x => x.line_id);
table.ForeignKey(
name: "f_k_recurring_journal_template_line_accounts_account_id",
column: x => x.account_id,
principalTable: "accounts",
principalColumn: "account_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_recurring_journal_template_line_recurring_journal_template_t~",
column: x => x.template_id,
principalTable: "recurring_journal_template",
principalColumn: "template_id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "tax_code",
columns: table => new
{
tax_code_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
tax_type_id = table.Column(type: "int", nullable: false),
code = table.Column(type: "varchar(20)", maxLength: 20, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
name = table.Column(type: "varchar(100)", maxLength: 100, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
rate_percent = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false),
calculation_basis = table.Column(type: "int", nullable: false, defaultValue: 1),
applies_to = table.Column(type: "int", nullable: false),
output_tax_account_id = table.Column(type: "bigint", nullable: true),
input_tax_account_id = table.Column(type: "bigint", nullable: true),
effective_from = table.Column(type: "date", nullable: false),
effective_to = table.Column(type: "date", nullable: true),
is_active = table.Column(type: "tinyint(1)", nullable: false, defaultValue: true),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_tax_code", x => x.tax_code_id);
table.ForeignKey(
name: "f_k_tax_code_accounts_input_tax_account_id",
column: x => x.input_tax_account_id,
principalTable: "accounts",
principalColumn: "account_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_tax_code_accounts_output_tax_account_id",
column: x => x.output_tax_account_id,
principalTable: "accounts",
principalColumn: "account_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_tax_code_tax_type_tax_type_id",
column: x => x.tax_type_id,
principalTable: "tax_type",
principalColumn: "tax_type_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "journal_entry",
columns: table => new
{
journal_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
journal_no = table.Column(type: "varchar(30)", maxLength: 30, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
period_id = table.Column(type: "int", nullable: false),
entry_date = table.Column(type: "date", nullable: false),
journal_type = table.Column(type: "varchar(30)", maxLength: 30, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
source_module = table.Column(type: "varchar(30)", maxLength: 30, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
reference = table.Column(type: "varchar(100)", maxLength: 100, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
narration = table.Column(type: "text", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
is_posted = table.Column(type: "tinyint(1)", nullable: false, defaultValue: false),
is_reversed = table.Column(type: "tinyint(1)", nullable: false, defaultValue: false),
reversal_of_id = table.Column(type: "bigint", nullable: true),
entry_status = table.Column(type: "int", nullable: false),
prepared_by = table.Column(type: "varchar(100)", maxLength: 100, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_journal_entry", x => x.journal_id);
table.ForeignKey(
name: "f_k_journal_entry_accounting_period_period_id",
column: x => x.period_id,
principalTable: "accounting_period",
principalColumn: "period_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_journal_entry_journal_entry_reversal_of_id",
column: x => x.reversal_of_id,
principalTable: "journal_entry",
principalColumn: "journal_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "period_lock_log",
columns: table => new
{
log_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
period_id = table.Column(type: "int", nullable: false),
action = table.Column(type: "int", nullable: false),
module_locked = table.Column(type: "varchar(15)", maxLength: 15, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
reason = table.Column(type: "varchar(255)", maxLength: 255, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_period_lock_log", x => x.log_id);
table.ForeignKey(
name: "f_k_period_lock_log_accounting_period_period_id",
column: x => x.period_id,
principalTable: "accounting_period",
principalColumn: "period_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "budget_line",
columns: table => new
{
budget_line_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
budget_id = table.Column(type: "bigint", nullable: false),
account_id = table.Column(type: "bigint", nullable: false),
period_id = table.Column(type: "int", nullable: false),
cost_center_id = table.Column(type: "bigint", nullable: true),
budgeted_amount = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_budget_line", x => x.budget_line_id);
table.ForeignKey(
name: "f_k_budget_line_accounting_period_period_id",
column: x => x.period_id,
principalTable: "accounting_period",
principalColumn: "period_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_budget_line_accounts_account_id",
column: x => x.account_id,
principalTable: "accounts",
principalColumn: "account_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_budget_line_budget_budget_id",
column: x => x.budget_id,
principalTable: "budget",
principalColumn: "budget_id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "f_k_budget_line_cost_center_cost_center_id",
column: x => x.cost_center_id,
principalTable: "cost_center",
principalColumn: "cost_center_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "cheque_book",
columns: table => new
{
cheque_book_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
branch_id = table.Column(type: "bigint", nullable: false),
bank_account_id = table.Column(type: "bigint", nullable: false),
cheque_book_no = table.Column(type: "varchar(50)", maxLength: 50, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
start_cheque_no = table.Column(type: "varchar(30)", maxLength: 30, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
end_cheque_no = table.Column(type: "varchar(30)", maxLength: 30, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
total_leaves = table.Column(type: "int", nullable: false),
received_date = table.Column(type: "date", nullable: false),
status = table.Column(type: "int", nullable: false, defaultValue: 1),
description = table.Column(type: "text", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
is_active = table.Column(type: "tinyint(1)", nullable: false, defaultValue: true),
created_by = table.Column(type: "varchar(100)", maxLength: 100, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)"),
modified_by = table.Column(type: "varchar(100)", maxLength: 100, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
modified_at = table.Column(type: "datetime(6)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("p_k_cheque_book", x => x.cheque_book_id);
table.ForeignKey(
name: "f_k_cheque_book_bank_account_bank_account_id",
column: x => x.bank_account_id,
principalTable: "bank_account",
principalColumn: "bank_account_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "received_cheque",
columns: table => new
{
received_cheque_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
company_id = table.Column(type: "bigint", nullable: false),
branch_id = table.Column(type: "bigint", nullable: true),
received_from_type = table.Column(type: "int", nullable: false),
received_from_id = table.Column(type: "bigint", nullable: true),
received_from_name = table.Column(type: "varchar(200)", maxLength: 200, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
drawer_bank_name = table.Column(type: "varchar(150)", maxLength: 150, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
drawer_bank_branch = table.Column(type: "varchar(150)", maxLength: 150, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
account_holder_name = table.Column(type: "varchar(200)", maxLength: 200, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
cheque_no = table.Column(type: "varchar(30)", maxLength: 30, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
cheque_date = table.Column(type: "date", nullable: false),
amount = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false),
received_date = table.Column(type: "date", nullable: false),
deposit_bank_account_id = table.Column(type: "bigint", nullable: true),
deposit_date = table.Column(type: "date", nullable: true),
status = table.Column(type: "int", nullable: false, defaultValue: 1),
reference_type = table.Column(type: "varchar(100)", maxLength: 100, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
reference_id = table.Column(type: "bigint", nullable: true),
notes = table.Column(type: "text", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
created_by = table.Column(type: "varchar(100)", maxLength: 100, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_received_cheque", x => x.received_cheque_id);
table.ForeignKey(
name: "f_k_received_cheque_bank_account_deposit_bank_account_id",
column: x => x.deposit_bank_account_id,
principalTable: "bank_account",
principalColumn: "bank_account_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "cash_account",
columns: table => new
{
cash_account_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
account_name = table.Column(type: "varchar(150)", maxLength: 150, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
cash_account_type_id = table.Column(type: "int", nullable: false),
account_number = table.Column(type: "varchar(50)", maxLength: 50, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
gl_account_id = table.Column(type: "bigint", nullable: false),
currency_code = table.Column(type: "char(3)", maxLength: 3, nullable: false, defaultValue: "LKR")
.Annotation("MySql:CharSet", "utf8mb4"),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_cash_account", x => x.cash_account_id);
table.ForeignKey(
name: "f_k_cash_account_accounts_gl_account_id",
column: x => x.gl_account_id,
principalTable: "accounts",
principalColumn: "account_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_cash_account_cash_account_type_cash_account_type_id",
column: x => x.cash_account_type_id,
principalTable: "cash_account_type",
principalColumn: "cash_account_type_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_cash_account_currency_currency_code",
column: x => x.currency_code,
principalTable: "currency",
principalColumn: "currency_code",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "asset_disposal",
columns: table => new
{
disposal_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
asset_id = table.Column(type: "bigint", nullable: false),
disposal_date = table.Column(type: "date", nullable: false),
proceeds = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: true),
net_book_value_at_disposal = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: true),
gain_loss = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: true),
journal_id = table.Column(type: "bigint", nullable: true),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_asset_disposal", x => x.disposal_id);
table.ForeignKey(
name: "f_k_asset_disposal_fixed_asset_asset_id",
column: x => x.asset_id,
principalTable: "fixed_asset",
principalColumn: "asset_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_asset_disposal_journal_entry_journal_id",
column: x => x.journal_id,
principalTable: "journal_entry",
principalColumn: "journal_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "bank_statement_line",
columns: table => new
{
stmt_line_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
bank_account_id = table.Column(type: "bigint", nullable: false),
txn_date = table.Column(type: "date", nullable: false),
description = table.Column(type: "varchar(255)", maxLength: 255, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
amount = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false),
is_reconciled = table.Column(type: "tinyint(1)", nullable: false, defaultValue: false),
matched_journal_id = table.Column(type: "bigint", nullable: true),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_bank_statement_line", x => x.stmt_line_id);
table.ForeignKey(
name: "f_k_bank_statement_line_bank_account_bank_account_id",
column: x => x.bank_account_id,
principalTable: "bank_account",
principalColumn: "bank_account_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_bank_statement_line_journal_entry_matched_journal_id",
column: x => x.matched_journal_id,
principalTable: "journal_entry",
principalColumn: "journal_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "depreciation_schedule",
columns: table => new
{
schedule_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
asset_id = table.Column(type: "bigint", nullable: false),
period_id = table.Column(type: "int", nullable: false),
depreciation_amount = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false),
accumulated_depreciation = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false),
net_book_value = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false),
journal_id = table.Column(type: "bigint", nullable: true),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_depreciation_schedule", x => x.schedule_id);
table.ForeignKey(
name: "f_k_depreciation_schedule_accounting_period_period_id",
column: x => x.period_id,
principalTable: "accounting_period",
principalColumn: "period_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_depreciation_schedule_fixed_asset_asset_id",
column: x => x.asset_id,
principalTable: "fixed_asset",
principalColumn: "asset_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_depreciation_schedule_journal_entry_journal_id",
column: x => x.journal_id,
principalTable: "journal_entry",
principalColumn: "journal_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "journal_correction",
columns: table => new
{
correction_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
original_journal_id = table.Column(type: "bigint", nullable: false),
correction_journal_id = table.Column(type: "bigint", nullable: false),
correction_type = table.Column(type: "int", nullable: false),
reason = table.Column(type: "text", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
corrected_by = table.Column(type: "varchar(100)", maxLength: 100, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_journal_correction", x => x.correction_id);
table.ForeignKey(
name: "f_k_journal_correction_journal_entry_correction_journal_id",
column: x => x.correction_journal_id,
principalTable: "journal_entry",
principalColumn: "journal_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_journal_correction_journal_entry_original_journal_id",
column: x => x.original_journal_id,
principalTable: "journal_entry",
principalColumn: "journal_id",
onDelete: ReferentialAction.Restrict);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "journal_entry_line",
columns: table => new
{
line_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
journal_id = table.Column(type: "bigint", nullable: false),
account_id = table.Column(type: "bigint", nullable: false),
debit_amount = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false, defaultValue: 0m),
credit_amount = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false, defaultValue: 0m),
currency_code = table.Column(type: "char(3)", maxLength: 3, nullable: false, defaultValue: "LKR")
.Annotation("MySql:CharSet", "utf8mb4"),
exchange_rate = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false, defaultValue: 1m),
base_debit = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false, defaultValue: 0m),
base_credit = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: false, defaultValue: 0m),
cost_center_id = table.Column(type: "bigint", nullable: true),
memo = table.Column(type: "text", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
created_at = table.Column(type: "datetime(6)", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP(6)")
},
constraints: table =>
{
table.PrimaryKey("p_k_journal_entry_line", x => x.line_id);
table.CheckConstraint("CK_journal_entry_line_amounts_non_negative", "debit_amount >= 0 AND credit_amount >= 0");
table.CheckConstraint("CK_journal_entry_line_one_sided", "(debit_amount = 0 AND credit_amount > 0) OR (credit_amount = 0 AND debit_amount > 0)");
table.ForeignKey(
name: "f_k_journal_entry_line_accounts_account_id",
column: x => x.account_id,
principalTable: "accounts",
principalColumn: "account_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_journal_entry_line_cost_center_cost_center_id",
column: x => x.cost_center_id,
principalTable: "cost_center",
principalColumn: "cost_center_id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_journal_entry_line_currency_currency_code",
column: x => x.currency_code,
principalTable: "currency",
principalColumn: "currency_code",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "f_k_journal_entry_line_journal_entry_journal_id",
column: x => x.journal_id,
principalTable: "journal_entry",
principalColumn: "journal_id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "cheque_page",
columns: table => new
{
cheque_page_id = table.Column(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
cheque_book_id = table.Column(type: "bigint", nullable: false),
cheque_no = table.Column(type: "varchar(30)", maxLength: 30, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
issue_status = table.Column(type: "int", nullable: false, defaultValue: 1),
payee_type = table.Column(type: "int", nullable: true),
payee_id = table.Column(type: "bigint", nullable: true),
payee_name = table.Column(type: "varchar(200)", maxLength: 200, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
issue_date = table.Column(type: "date", nullable: true),
amount = table.Column(type: "decimal(38,10)", precision: 38, scale: 10, nullable: true),
currency_code = table.Column(type: "char(3)", maxLength: 3, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
voucher_id = table.Column(type: "bigint", nullable: true),
reference_no = table.Column