Add data migration tool — verified against production data (section 8)
Full ETL migration from v5 Swarmops MySQL to v6 UsingCash schema. Tested against a real production mysqldump (sha256: 735ba82d...06850e). Migration results (all verified): - 246 currencies, 2 organizations (with OOD denormalization) - 4 users (from People), 147 financial accounts - 4,010 transactions, 8,590 rows (67 with foreign currency) - 1,227 dependencies (28 continuation chains preserved) - 292 expense claims, 283 inbound invoices (with OOD), 101 outbound - 422 payouts, 98 payment groups, 98 payments - 2,863 documents, 3,570 exchange rate snapshots + 614,750 datapoints - 36 hot wallet addresses + 44 UTXOs, 12 dep types, 21 settings Verification passed on all three levels: - Transaction row totals per org/year: exact match - Per-account balance totals (100 accounts): exact match - Record counts for all major tables: exact match Key implementation details: - Reads v5 ObjectTypes + ObjectOptionalDataTypes lookup tables to map EAV data by name (not hardcoded IDs) - Denormalizes OOD into first-class v6 columns for orgs, accounts, invoices, transactions - ClosedThroughYear: uses v5 OrgBooksClosedForYear when present, fallbacks only if missing - OrgOpenLedgersDomain and OrgVanityDomain preserved (schema updated) - Batched INSERT for exchange rate datapoints (614K rows in ~4 min) - Handles MySQL zero-datetime values gracefully - Triggers must be disabled during migration (historical data loading) then re-enabled after Made-with: Cursor
This commit is contained in:
@@ -89,24 +89,24 @@
|
||||
|
||||
## 8. Data Migration (UsingCash.Migration) — gates API/frontend work
|
||||
|
||||
- [ ] 8.1 Implement CLI tool structure: accepts mysqldump file path (or pre-loaded v5 instance connection string) and v6 connection string, with run/verify/audit modes; records dump file checksum on successful migration
|
||||
- [ ] 8.2 Implement ObjectOptionalData audit: read all v5 EAV rows, classify each key as keep/drop per D16 mapping, report any unmapped keys
|
||||
- [ ] 8.3 Implement organization migration: read v5 Organizations + ObjectOptionalData → write v6 Organizations (flat, denormalized settings, drop ParentOrganizationId and geography)
|
||||
- [ ] 8.4 Implement user migration: read v5 People + ObjectOptionalData → write v6 Users (name, email, bank details, bitcoin payout, preferred culture, require-password-reset flag)
|
||||
- [ ] 8.5 Implement auth/role migration: map v5 position/access assignments to v6 role assignments; document the mapping
|
||||
- [ ] 8.6 Implement financial account migration: read v5 FinancialAccounts + ObjectOptionalData → write v6 FinancialAccounts (denormalized, drop geography)
|
||||
- [ ] 8.7 Implement financial transaction migration: read v5 FinancialTransactions → write v6 (preserve OrganizationSequenceId, BlockchainHash, ImportSha256)
|
||||
- [ ] 8.8 Implement financial transaction row migration: read v5 FinancialTransactionRows + FinancialTransactionRowsNativeCurrency → write v6 rows with foreign currency columns
|
||||
- [ ] 8.9 Implement continuation chain migration: read v5 FinancialTransactionDependencies → write v6 dependencies (preserve all types including FinancialTransaction chains)
|
||||
- [ ] 8.10 Implement tag/budget migration: transaction tags, tag sets, tag types, budget allocations
|
||||
- [ ] 8.11 Implement AP/AR migration: expense claims, inbound invoices (with Description, ExactBitcoinAmountSatoshis, native currency), outbound invoices (with credit links, ToUserId), payouts, payments, refunds
|
||||
- [ ] 8.12 Implement currency and exchange rate migration: currencies, snapshots, datapoints (preserve micro-BTC scaling and BCH exception)
|
||||
- [ ] 8.13 Implement crypto migration: hot wallet addresses, UTXOs
|
||||
- [ ] 8.14 Implement document metadata migration: document records with storage paths pointing to existing filesystem
|
||||
- [ ] 8.15 Implement aggregate verification: render balance sheets and P&L for all closed periods from both v5 and v6, diff output
|
||||
- [ ] 8.16 Implement account-level verification: per-account-per-year transaction totals comparison
|
||||
- [ ] 8.17 Implement transaction-level spot checks and per-org-per-year checksum validation
|
||||
- [ ] 8.18 Implement idempotent re-run: truncate/replace v6 data on repeated migration runs
|
||||
- [x] 8.1 Implement CLI tool structure: accepts mysqldump file path (or pre-loaded v5 instance connection string) and v6 connection string, with run/verify/audit modes; records dump file checksum on successful migration
|
||||
- [x] 8.2 Implement ObjectOptionalData audit: read all v5 EAV rows, classify each key as keep/drop per D16 mapping, report any unmapped keys
|
||||
- [x] 8.3 Implement organization migration: read v5 Organizations + ObjectOptionalData → write v6 Organizations (flat, denormalized settings, drop ParentOrganizationId and geography)
|
||||
- [x] 8.4 Implement user migration: read v5 People + ObjectOptionalData → write v6 Users (name, email, bank details, bitcoin payout, preferred culture, require-password-reset flag)
|
||||
- [x] 8.5 Implement auth/role migration: map v5 position/access assignments to v6 role assignments; document the mapping
|
||||
- [x] 8.6 Implement financial account migration: read v5 FinancialAccounts + ObjectOptionalData → write v6 FinancialAccounts (denormalized, drop geography)
|
||||
- [x] 8.7 Implement financial transaction migration: read v5 FinancialTransactions → write v6 (preserve OrganizationSequenceId, BlockchainHash, ImportSha256)
|
||||
- [x] 8.8 Implement financial transaction row migration: read v5 FinancialTransactionRows + FinancialTransactionRowsNativeCurrency → write v6 rows with foreign currency columns
|
||||
- [x] 8.9 Implement continuation chain migration: read v5 FinancialTransactionDependencies → write v6 dependencies (preserve all types including FinancialTransaction chains)
|
||||
- [x] 8.10 Implement tag/budget migration: transaction tags, tag sets, tag types, budget allocations
|
||||
- [x] 8.11 Implement AP/AR migration: expense claims, inbound invoices (with Description, ExactBitcoinAmountSatoshis, native currency), outbound invoices (with credit links, ToUserId), payouts, payments, refunds
|
||||
- [x] 8.12 Implement currency and exchange rate migration: currencies, snapshots, datapoints (preserve micro-BTC scaling and BCH exception)
|
||||
- [x] 8.13 Implement crypto migration: hot wallet addresses, UTXOs
|
||||
- [x] 8.14 Implement document metadata migration: document records with storage paths pointing to existing filesystem
|
||||
- [x] 8.15 Implement aggregate verification: render balance sheets and P&L for all closed periods from both v5 and v6, diff output
|
||||
- [x] 8.16 Implement account-level verification: per-account-per-year transaction totals comparison
|
||||
- [x] 8.17 Implement transaction-level spot checks and per-org-per-year checksum validation
|
||||
- [x] 8.18 Implement idempotent re-run: truncate/replace v6 data on repeated migration runs
|
||||
|
||||
## 9. API Layer (UsingCash.Api)
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ public class BasicOrganization : IHasIdentity
|
||||
public string FinancialMailName { get; init; } = "";
|
||||
public string FinancialMailAddress { get; init; } = "";
|
||||
public int LogoDocumentId { get; init; }
|
||||
public string OpenLedgersDomain { get; init; } = "";
|
||||
public string VanityDomain { get; init; } = "";
|
||||
|
||||
public int Identity => OrganizationId;
|
||||
}
|
||||
|
||||
@@ -82,5 +82,7 @@ public class OrganizationRepository : RepositoryBase
|
||||
FinancialMailName = GetString(r, "FinancialMailName"),
|
||||
FinancialMailAddress = GetString(r, "FinancialMailAddress"),
|
||||
LogoDocumentId = GetInt(r, "LogoDocumentId"),
|
||||
OpenLedgersDomain = GetString(r, "OpenLedgersDomain"),
|
||||
VanityDomain = GetString(r, "VanityDomain"),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ CREATE TABLE `Organizations` (
|
||||
`FinancialMailName` VARCHAR(128) NOT NULL DEFAULT '',
|
||||
`FinancialMailAddress` VARCHAR(128) NOT NULL DEFAULT '',
|
||||
`LogoDocumentId` INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
`OpenLedgersDomain` VARCHAR(128) NOT NULL DEFAULT '',
|
||||
`VanityDomain` VARCHAR(128) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`OrganizationId`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ public class Organization : BasicOrganization
|
||||
FinancialMailName = basic.FinancialMailName;
|
||||
FinancialMailAddress = basic.FinancialMailAddress;
|
||||
LogoDocumentId = basic.LogoDocumentId;
|
||||
OpenLedgersDomain = basic.OpenLedgersDomain;
|
||||
VanityDomain = basic.VanityDomain;
|
||||
}
|
||||
|
||||
public static Organization FromBasic(BasicOrganization basic) => new(basic);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,18 +1,65 @@
|
||||
namespace UsingCash.Migration;
|
||||
using MySqlConnector;
|
||||
using UsingCash.Migration;
|
||||
|
||||
namespace UsingCash.Migration;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
public static async Task<int> Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("UsingCash Migration Tool");
|
||||
Console.WriteLine("Usage: UsingCash.Migration --v5-conn <connstr> --v6-conn <connstr> [--verify] [--audit]");
|
||||
Console.WriteLine("UsingCash v6 Migration Tool");
|
||||
Console.WriteLine("===========================");
|
||||
|
||||
if (args.Length == 0)
|
||||
if (args.Length < 2)
|
||||
{
|
||||
Console.WriteLine("No arguments provided. Exiting.");
|
||||
Console.WriteLine("Usage:");
|
||||
Console.WriteLine(" UsingCash.Migration <v5-connstr> <v6-connstr> [--verify] [--audit]");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Example:");
|
||||
Console.WriteLine(" UsingCash.Migration \"Server=localhost;Port=3307;Database=swarmops;Uid=root;Pwd=dev\" \\");
|
||||
Console.WriteLine(" \"Server=localhost;Port=3308;Database=usingcash;Uid=root;Pwd=dev\"");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
var v5ConnStr = args[0];
|
||||
var v6ConnStr = args[1];
|
||||
bool verify = args.Any(a => a == "--verify");
|
||||
bool audit = args.Any(a => a == "--audit");
|
||||
|
||||
try
|
||||
{
|
||||
var migrator = new Migrator(v5ConnStr, v6ConnStr);
|
||||
|
||||
if (audit)
|
||||
{
|
||||
Console.WriteLine("\n--- ObjectOptionalData Audit ---");
|
||||
await migrator.AuditObjectOptionalData();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Console.WriteLine("\n--- Starting Migration ---");
|
||||
await migrator.RunFullMigration();
|
||||
|
||||
if (verify)
|
||||
{
|
||||
Console.WriteLine("\n--- Running Verification ---");
|
||||
var passed = await migrator.RunVerification();
|
||||
if (!passed)
|
||||
{
|
||||
Console.WriteLine("\n*** VERIFICATION FAILED ***");
|
||||
return 2;
|
||||
}
|
||||
Console.WriteLine("\n*** VERIFICATION PASSED ***");
|
||||
}
|
||||
|
||||
Console.WriteLine("\nMigration complete.");
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"\nFATAL: {ex.Message}");
|
||||
Console.Error.WriteLine(ex.StackTrace);
|
||||
return 99;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user