20210525073538_addMembership.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. using System;
  2. using Microsoft.EntityFrameworkCore.Migrations;
  3. namespace Gateway.POS.Migrations
  4. {
  5. public partial class addMembership : Migration
  6. {
  7. protected override void Up(MigrationBuilder migrationBuilder)
  8. {
  9. migrationBuilder.AddColumn<int>(
  10. name: "MembershipProfitAccountRechargeId",
  11. table: "Transactions",
  12. type: "INTEGER",
  13. nullable: true);
  14. migrationBuilder.AddColumn<int>(
  15. name: "MembershipProfitAccountRedeemId",
  16. table: "Transactions",
  17. type: "INTEGER",
  18. nullable: true);
  19. migrationBuilder.AddColumn<int>(
  20. name: "TransactionSubType",
  21. table: "Transactions",
  22. type: "INTEGER",
  23. nullable: true);
  24. migrationBuilder.AddColumn<string>(
  25. name: "CardReaderName",
  26. table: "Payments",
  27. type: "TEXT",
  28. nullable: true);
  29. migrationBuilder.AddColumn<int>(
  30. name: "TargetMembershipAccountId",
  31. table: "Payments",
  32. type: "INTEGER",
  33. nullable: true);
  34. migrationBuilder.AddColumn<int>(
  35. name: "TargetMembershipSubAccountId",
  36. table: "Payments",
  37. type: "INTEGER",
  38. nullable: true);
  39. migrationBuilder.CreateTable(
  40. name: "MembershipAccounts",
  41. columns: table => new
  42. {
  43. Id = table.Column<int>(type: "INTEGER", nullable: false)
  44. .Annotation("Sqlite:Autoincrement", true),
  45. Name = table.Column<string>(type: "TEXT", nullable: false),
  46. CompanyName = table.Column<string>(type: "TEXT", nullable: true),
  47. Age = table.Column<int>(type: "INTEGER", nullable: false),
  48. PhoneNumber = table.Column<string>(type: "TEXT", nullable: true),
  49. Address = table.Column<string>(type: "TEXT", nullable: true),
  50. Email = table.Column<string>(type: "TEXT", nullable: true),
  51. Birth = table.Column<DateTime>(type: "TEXT", nullable: true),
  52. IsMale = table.Column<bool>(type: "INTEGER", nullable: false),
  53. Description = table.Column<string>(type: "TEXT", nullable: true),
  54. InvoiceTaxNumber = table.Column<string>(type: "TEXT", nullable: true),
  55. InvoiceCompanyName = table.Column<string>(type: "TEXT", nullable: true),
  56. MembershipLevel = table.Column<int>(type: "INTEGER", nullable: true),
  57. AllowSubAccountAccessProfitAccounts = table.Column<bool>(type: "INTEGER", nullable: false),
  58. EnableProfitAccountBalanceChangeNotify = table.Column<bool>(type: "INTEGER", nullable: false),
  59. ConsumeRestrictionComplexData = table.Column<string>(type: "TEXT", nullable: true),
  60. ClientSideTimestamp = table.Column<DateTime>(type: "TEXT", nullable: true),
  61. ServerSideLastModifiedTimestamp = table.Column<DateTime>(type: "TEXT", nullable: true),
  62. ServerSideCreatedTimestamp = table.Column<DateTime>(type: "TEXT", nullable: false),
  63. SuspendStateStartTime = table.Column<DateTime>(type: "TEXT", nullable: true),
  64. SuspendStateEndTime = table.Column<DateTime>(type: "TEXT", nullable: true),
  65. CreateByOperatorId = table.Column<int>(type: "INTEGER", nullable: true)
  66. },
  67. constraints: table =>
  68. {
  69. table.PrimaryKey("PK_MembershipAccounts", x => x.Id);
  70. table.ForeignKey(
  71. name: "FK_MembershipAccounts_Operators_CreateByOperatorId",
  72. column: x => x.CreateByOperatorId,
  73. principalTable: "Operators",
  74. principalColumn: "Id",
  75. onDelete: ReferentialAction.Restrict);
  76. });
  77. migrationBuilder.CreateTable(
  78. name: "MembershipTags",
  79. columns: table => new
  80. {
  81. Id = table.Column<int>(type: "INTEGER", nullable: false)
  82. .Annotation("Sqlite:Autoincrement", true),
  83. Name = table.Column<string>(type: "TEXT", nullable: true),
  84. Description = table.Column<string>(type: "TEXT", nullable: true)
  85. },
  86. constraints: table =>
  87. {
  88. table.PrimaryKey("PK_MembershipTags", x => x.Id);
  89. });
  90. migrationBuilder.CreateTable(
  91. name: "MembershipSubAccounts",
  92. columns: table => new
  93. {
  94. Id = table.Column<int>(type: "INTEGER", nullable: false)
  95. .Annotation("Sqlite:Autoincrement", true),
  96. MembershipAccountId = table.Column<int>(type: "INTEGER", nullable: false),
  97. AccountState = table.Column<int>(type: "INTEGER", nullable: false),
  98. LastAccountStateUpdateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
  99. LastAccountStateUpdateReason = table.Column<string>(type: "TEXT", nullable: true),
  100. SuspendStateStartTime = table.Column<DateTime>(type: "TEXT", nullable: true),
  101. SuspendStateEndTime = table.Column<DateTime>(type: "TEXT", nullable: true),
  102. ServerSideCreatedTimestamp = table.Column<DateTime>(type: "TEXT", nullable: false),
  103. ServerSideLastModifiedTimestamp = table.Column<DateTime>(type: "TEXT", nullable: true),
  104. SubAccountHolderName = table.Column<string>(type: "TEXT", nullable: true),
  105. SubAccountHolderPhoneNumber = table.Column<string>(type: "TEXT", nullable: true),
  106. SubAccountHolderEmail = table.Column<string>(type: "TEXT", nullable: true),
  107. SubAccountHolderAddress = table.Column<string>(type: "TEXT", nullable: true),
  108. EnableProfitAccountBalanceChangeNotify = table.Column<bool>(type: "INTEGER", nullable: false),
  109. MembershipLevel = table.Column<int>(type: "INTEGER", nullable: true),
  110. ConsumeRestrictionComplexData = table.Column<string>(type: "TEXT", nullable: true),
  111. Description = table.Column<string>(type: "TEXT", nullable: true),
  112. CreateByOperatorId = table.Column<int>(type: "INTEGER", nullable: true)
  113. },
  114. constraints: table =>
  115. {
  116. table.PrimaryKey("PK_MembershipSubAccounts", x => x.Id);
  117. table.ForeignKey(
  118. name: "FK_MembershipSubAccounts_MembershipAccounts_MembershipAccountId",
  119. column: x => x.MembershipAccountId,
  120. principalTable: "MembershipAccounts",
  121. principalColumn: "Id",
  122. onDelete: ReferentialAction.Cascade);
  123. table.ForeignKey(
  124. name: "FK_MembershipSubAccounts_Operators_CreateByOperatorId",
  125. column: x => x.CreateByOperatorId,
  126. principalTable: "Operators",
  127. principalColumn: "Id",
  128. onDelete: ReferentialAction.Restrict);
  129. });
  130. migrationBuilder.CreateTable(
  131. name: "MembershipAccount_M2M_MembershipTags",
  132. columns: table => new
  133. {
  134. MembershipAccountId = table.Column<int>(type: "INTEGER", nullable: false),
  135. MembershipTagId = table.Column<int>(type: "INTEGER", nullable: false)
  136. },
  137. constraints: table =>
  138. {
  139. table.PrimaryKey("PK_MembershipAccount_M2M_MembershipTags", x => new { x.MembershipTagId, x.MembershipAccountId });
  140. table.ForeignKey(
  141. name: "FK_MembershipAccount_M2M_MembershipTags_MembershipAccounts_MembershipAccountId",
  142. column: x => x.MembershipAccountId,
  143. principalTable: "MembershipAccounts",
  144. principalColumn: "Id",
  145. onDelete: ReferentialAction.Cascade);
  146. table.ForeignKey(
  147. name: "FK_MembershipAccount_M2M_MembershipTags_MembershipTags_MembershipTagId",
  148. column: x => x.MembershipTagId,
  149. principalTable: "MembershipTags",
  150. principalColumn: "Id",
  151. onDelete: ReferentialAction.Cascade);
  152. });
  153. migrationBuilder.CreateTable(
  154. name: "MembershipProfitAccounts",
  155. columns: table => new
  156. {
  157. Id = table.Column<int>(type: "INTEGER", nullable: false)
  158. .Annotation("Sqlite:Autoincrement", true),
  159. RedeemAuthMode = table.Column<int>(type: "INTEGER", nullable: false),
  160. RedeemAuthPassword = table.Column<string>(type: "TEXT", nullable: true),
  161. ProfitType = table.Column<int>(type: "INTEGER", nullable: false),
  162. Balance = table.Column<double>(type: "REAL", nullable: true),
  163. BalanceComplexData = table.Column<string>(type: "TEXT", nullable: true),
  164. MembershipAccountId = table.Column<int>(type: "INTEGER", nullable: true),
  165. MembershipSubAccountId = table.Column<int>(type: "INTEGER", nullable: true),
  166. ServerSideLastModifiedTimestamp = table.Column<DateTime>(type: "TEXT", nullable: true),
  167. ServerSideCreatedTimestamp = table.Column<DateTime>(type: "TEXT", nullable: false)
  168. },
  169. constraints: table =>
  170. {
  171. table.PrimaryKey("PK_MembershipProfitAccounts", x => x.Id);
  172. table.ForeignKey(
  173. name: "FK_MembershipProfitAccounts_MembershipAccounts_MembershipAccountId",
  174. column: x => x.MembershipAccountId,
  175. principalTable: "MembershipAccounts",
  176. principalColumn: "Id",
  177. onDelete: ReferentialAction.Restrict);
  178. table.ForeignKey(
  179. name: "FK_MembershipProfitAccounts_MembershipSubAccounts_MembershipSubAccountId",
  180. column: x => x.MembershipSubAccountId,
  181. principalTable: "MembershipSubAccounts",
  182. principalColumn: "Id",
  183. onDelete: ReferentialAction.Restrict);
  184. });
  185. migrationBuilder.CreateTable(
  186. name: "MembershipSubAccount_M2M_MembershipTags",
  187. columns: table => new
  188. {
  189. MembershipSubAccountId = table.Column<int>(type: "INTEGER", nullable: false),
  190. MembershipTagId = table.Column<int>(type: "INTEGER", nullable: false)
  191. },
  192. constraints: table =>
  193. {
  194. table.PrimaryKey("PK_MembershipSubAccount_M2M_MembershipTags", x => new { x.MembershipTagId, x.MembershipSubAccountId });
  195. table.ForeignKey(
  196. name: "FK_MembershipSubAccount_M2M_MembershipTags_MembershipSubAccounts_MembershipSubAccountId",
  197. column: x => x.MembershipSubAccountId,
  198. principalTable: "MembershipSubAccounts",
  199. principalColumn: "Id",
  200. onDelete: ReferentialAction.Cascade);
  201. table.ForeignKey(
  202. name: "FK_MembershipSubAccount_M2M_MembershipTags_MembershipTags_MembershipTagId",
  203. column: x => x.MembershipTagId,
  204. principalTable: "MembershipTags",
  205. principalColumn: "Id",
  206. onDelete: ReferentialAction.Cascade);
  207. });
  208. migrationBuilder.CreateTable(
  209. name: "MembershipSubAccountIdentities",
  210. columns: table => new
  211. {
  212. Id = table.Column<int>(type: "INTEGER", nullable: false)
  213. .Annotation("Sqlite:Autoincrement", true),
  214. MembershipSubAccountId = table.Column<int>(type: "INTEGER", nullable: false),
  215. IdentityCarrierType = table.Column<int>(type: "INTEGER", nullable: false),
  216. Identity = table.Column<string>(type: "TEXT", nullable: true),
  217. Description = table.Column<string>(type: "TEXT", nullable: true)
  218. },
  219. constraints: table =>
  220. {
  221. table.PrimaryKey("PK_MembershipSubAccountIdentities", x => x.Id);
  222. table.ForeignKey(
  223. name: "FK_MembershipSubAccountIdentities_MembershipSubAccounts_MembershipSubAccountId",
  224. column: x => x.MembershipSubAccountId,
  225. principalTable: "MembershipSubAccounts",
  226. principalColumn: "Id",
  227. onDelete: ReferentialAction.Cascade);
  228. });
  229. migrationBuilder.CreateTable(
  230. name: "MembershipProfitAccountRecharges",
  231. columns: table => new
  232. {
  233. Id = table.Column<int>(type: "INTEGER", nullable: false)
  234. .Annotation("Sqlite:Autoincrement", true),
  235. RechargeSource = table.Column<int>(type: "INTEGER", nullable: false),
  236. RechargeAmount = table.Column<double>(type: "REAL", nullable: true),
  237. ProfitAccountAmountBalance = table.Column<decimal>(type: "TEXT", nullable: true),
  238. InvoiceIssuedDateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
  239. Description = table.Column<string>(type: "TEXT", nullable: true),
  240. Timestamp = table.Column<DateTime>(type: "TEXT", nullable: false),
  241. MembershipProfitAccountId = table.Column<int>(type: "INTEGER", nullable: false),
  242. CreateByOperatorId = table.Column<int>(type: "INTEGER", nullable: true)
  243. },
  244. constraints: table =>
  245. {
  246. table.PrimaryKey("PK_MembershipProfitAccountRecharges", x => x.Id);
  247. table.ForeignKey(
  248. name: "FK_MembershipProfitAccountRecharges_MembershipProfitAccounts_MembershipProfitAccountId",
  249. column: x => x.MembershipProfitAccountId,
  250. principalTable: "MembershipProfitAccounts",
  251. principalColumn: "Id",
  252. onDelete: ReferentialAction.Cascade);
  253. table.ForeignKey(
  254. name: "FK_MembershipProfitAccountRecharges_Operators_CreateByOperatorId",
  255. column: x => x.CreateByOperatorId,
  256. principalTable: "Operators",
  257. principalColumn: "Id",
  258. onDelete: ReferentialAction.Restrict);
  259. });
  260. migrationBuilder.CreateTable(
  261. name: "MembershipProfitAccountRedeems",
  262. columns: table => new
  263. {
  264. Id = table.Column<int>(type: "INTEGER", nullable: false)
  265. .Annotation("Sqlite:Autoincrement", true),
  266. Purpose = table.Column<string>(type: "TEXT", nullable: true),
  267. RedeemedProfitAmount = table.Column<double>(type: "REAL", nullable: true),
  268. RedeemedProfitComplexData = table.Column<string>(type: "TEXT", nullable: true),
  269. ProfitAccountAmountBalance = table.Column<decimal>(type: "TEXT", nullable: true),
  270. Description = table.Column<string>(type: "TEXT", nullable: true),
  271. Timestamp = table.Column<DateTime>(type: "TEXT", nullable: false),
  272. MembershipProfitAccountId = table.Column<int>(type: "INTEGER", nullable: false),
  273. CreateByOperatorId = table.Column<int>(type: "INTEGER", nullable: true)
  274. },
  275. constraints: table =>
  276. {
  277. table.PrimaryKey("PK_MembershipProfitAccountRedeems", x => x.Id);
  278. table.ForeignKey(
  279. name: "FK_MembershipProfitAccountRedeems_MembershipProfitAccounts_MembershipProfitAccountId",
  280. column: x => x.MembershipProfitAccountId,
  281. principalTable: "MembershipProfitAccounts",
  282. principalColumn: "Id",
  283. onDelete: ReferentialAction.Cascade);
  284. table.ForeignKey(
  285. name: "FK_MembershipProfitAccountRedeems_Operators_CreateByOperatorId",
  286. column: x => x.CreateByOperatorId,
  287. principalTable: "Operators",
  288. principalColumn: "Id",
  289. onDelete: ReferentialAction.Restrict);
  290. });
  291. migrationBuilder.CreateIndex(
  292. name: "IX_Transactions_MembershipProfitAccountRechargeId",
  293. table: "Transactions",
  294. column: "MembershipProfitAccountRechargeId");
  295. migrationBuilder.CreateIndex(
  296. name: "IX_Transactions_MembershipProfitAccountRedeemId",
  297. table: "Transactions",
  298. column: "MembershipProfitAccountRedeemId");
  299. migrationBuilder.CreateIndex(
  300. name: "IX_MembershipAccount_M2M_MembershipTags_MembershipAccountId",
  301. table: "MembershipAccount_M2M_MembershipTags",
  302. column: "MembershipAccountId");
  303. migrationBuilder.CreateIndex(
  304. name: "IX_MembershipAccounts_CreateByOperatorId",
  305. table: "MembershipAccounts",
  306. column: "CreateByOperatorId");
  307. migrationBuilder.CreateIndex(
  308. name: "IX_MembershipAccounts_Name_CompanyName_PhoneNumber",
  309. table: "MembershipAccounts",
  310. columns: new[] { "Name", "CompanyName", "PhoneNumber" });
  311. migrationBuilder.CreateIndex(
  312. name: "IX_MembershipProfitAccountRecharges_CreateByOperatorId",
  313. table: "MembershipProfitAccountRecharges",
  314. column: "CreateByOperatorId");
  315. migrationBuilder.CreateIndex(
  316. name: "IX_MembershipProfitAccountRecharges_MembershipProfitAccountId",
  317. table: "MembershipProfitAccountRecharges",
  318. column: "MembershipProfitAccountId");
  319. migrationBuilder.CreateIndex(
  320. name: "IX_MembershipProfitAccountRedeems_CreateByOperatorId",
  321. table: "MembershipProfitAccountRedeems",
  322. column: "CreateByOperatorId");
  323. migrationBuilder.CreateIndex(
  324. name: "IX_MembershipProfitAccountRedeems_MembershipProfitAccountId",
  325. table: "MembershipProfitAccountRedeems",
  326. column: "MembershipProfitAccountId");
  327. migrationBuilder.CreateIndex(
  328. name: "IX_MembershipProfitAccounts_MembershipAccountId",
  329. table: "MembershipProfitAccounts",
  330. column: "MembershipAccountId");
  331. migrationBuilder.CreateIndex(
  332. name: "IX_MembershipProfitAccounts_MembershipSubAccountId",
  333. table: "MembershipProfitAccounts",
  334. column: "MembershipSubAccountId");
  335. migrationBuilder.CreateIndex(
  336. name: "IX_MembershipSubAccount_M2M_MembershipTags_MembershipSubAccountId",
  337. table: "MembershipSubAccount_M2M_MembershipTags",
  338. column: "MembershipSubAccountId");
  339. migrationBuilder.CreateIndex(
  340. name: "IX_MembershipSubAccountIdentities_MembershipSubAccountId_Identity_IdentityCarrierType",
  341. table: "MembershipSubAccountIdentities",
  342. columns: new[] { "MembershipSubAccountId", "Identity", "IdentityCarrierType" },
  343. unique: true);
  344. migrationBuilder.CreateIndex(
  345. name: "IX_MembershipSubAccounts_CreateByOperatorId",
  346. table: "MembershipSubAccounts",
  347. column: "CreateByOperatorId");
  348. migrationBuilder.CreateIndex(
  349. name: "IX_MembershipSubAccounts_MembershipAccountId",
  350. table: "MembershipSubAccounts",
  351. column: "MembershipAccountId");
  352. migrationBuilder.CreateIndex(
  353. name: "IX_MembershipTags_Name",
  354. table: "MembershipTags",
  355. column: "Name",
  356. unique: true);
  357. migrationBuilder.AddForeignKey(
  358. name: "FK_Transactions_MembershipProfitAccountRecharges_MembershipProfitAccountRechargeId",
  359. table: "Transactions",
  360. column: "MembershipProfitAccountRechargeId",
  361. principalTable: "MembershipProfitAccountRecharges",
  362. principalColumn: "Id",
  363. onDelete: ReferentialAction.Restrict);
  364. migrationBuilder.AddForeignKey(
  365. name: "FK_Transactions_MembershipProfitAccountRedeems_MembershipProfitAccountRedeemId",
  366. table: "Transactions",
  367. column: "MembershipProfitAccountRedeemId",
  368. principalTable: "MembershipProfitAccountRedeems",
  369. principalColumn: "Id",
  370. onDelete: ReferentialAction.Restrict);
  371. }
  372. protected override void Down(MigrationBuilder migrationBuilder)
  373. {
  374. migrationBuilder.DropForeignKey(
  375. name: "FK_Transactions_MembershipProfitAccountRecharges_MembershipProfitAccountRechargeId",
  376. table: "Transactions");
  377. migrationBuilder.DropForeignKey(
  378. name: "FK_Transactions_MembershipProfitAccountRedeems_MembershipProfitAccountRedeemId",
  379. table: "Transactions");
  380. migrationBuilder.DropTable(
  381. name: "MembershipAccount_M2M_MembershipTags");
  382. migrationBuilder.DropTable(
  383. name: "MembershipProfitAccountRecharges");
  384. migrationBuilder.DropTable(
  385. name: "MembershipProfitAccountRedeems");
  386. migrationBuilder.DropTable(
  387. name: "MembershipSubAccount_M2M_MembershipTags");
  388. migrationBuilder.DropTable(
  389. name: "MembershipSubAccountIdentities");
  390. migrationBuilder.DropTable(
  391. name: "MembershipProfitAccounts");
  392. migrationBuilder.DropTable(
  393. name: "MembershipTags");
  394. migrationBuilder.DropTable(
  395. name: "MembershipSubAccounts");
  396. migrationBuilder.DropTable(
  397. name: "MembershipAccounts");
  398. migrationBuilder.DropIndex(
  399. name: "IX_Transactions_MembershipProfitAccountRechargeId",
  400. table: "Transactions");
  401. migrationBuilder.DropIndex(
  402. name: "IX_Transactions_MembershipProfitAccountRedeemId",
  403. table: "Transactions");
  404. migrationBuilder.DropColumn(
  405. name: "MembershipProfitAccountRechargeId",
  406. table: "Transactions");
  407. migrationBuilder.DropColumn(
  408. name: "MembershipProfitAccountRedeemId",
  409. table: "Transactions");
  410. migrationBuilder.DropColumn(
  411. name: "TransactionSubType",
  412. table: "Transactions");
  413. migrationBuilder.DropColumn(
  414. name: "CardReaderName",
  415. table: "Payments");
  416. migrationBuilder.DropColumn(
  417. name: "TargetMembershipAccountId",
  418. table: "Payments");
  419. migrationBuilder.DropColumn(
  420. name: "TargetMembershipSubAccountId",
  421. table: "Payments");
  422. }
  423. }
  424. }