From 7f89a29b9440de796afaac906f838728ed1d94ea Mon Sep 17 00:00:00 2001 From: Jukka Lampikoski Date: Tue, 10 Mar 2026 11:06:08 +0200 Subject: [PATCH] Fix migration check: detect unmigrated data by checking data/customers.json The previous check (directory existence) failed on production because git pull created data/companies/ from committed config.json, causing the migration to be skipped while customer data remained in data/ root. Co-Authored-By: Claude Opus 4.6 --- api.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/api.php b/api.php index b68f1ca..cf7e036 100644 --- a/api.php +++ b/api.php @@ -120,18 +120,16 @@ function saveCompanyConfig(array $config): void { } function runMigration(): void { - // Tarkista onko migraatio jo tehty $companiesDir = DATA_DIR . '/companies'; - if (file_exists($companiesDir) && is_dir($companiesDir)) return; - // Tarkista onko vanha data olemassa (pre-multitenant) + // Tarkista onko vanha data olemassa juuressa (pre-multitenant) $oldCustomers = DATA_DIR . '/customers.json'; - if (!file_exists($oldCustomers)) return; + if (!file_exists($oldCustomers)) return; // Ei vanhaa dataa → ei migraatiota - // Luo yritykshakemisto - mkdir($companiesDir, 0755, true); + // Vanha data löytyy juuresta → siirretään yrityksen alle + if (!file_exists($companiesDir)) mkdir($companiesDir, 0755, true); $cuitunetDir = $companiesDir . '/cuitunet'; - mkdir($cuitunetDir, 0755, true); + if (!file_exists($cuitunetDir)) mkdir($cuitunetDir, 0755, true); // Luo companies.json $companies = [[