Fix data loss: remove data files from git, add gitignore, auto-recover
- Remove data/companies.json and data/companies/cuitunet/config.json from git (tracked data files get overwritten on every deploy, causing data loss) - Add data/companies/*/ and data/tickets.json to .gitignore - Migration now auto-recovers companies.json and config.json if missing (handles case where git clean removes untracked data files) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,7 +4,10 @@ data/changelog.json
|
|||||||
data/archive.json
|
data/archive.json
|
||||||
data/leads.json
|
data/leads.json
|
||||||
data/config.json
|
data/config.json
|
||||||
|
data/tickets.json
|
||||||
data/reset_tokens.json
|
data/reset_tokens.json
|
||||||
data/login_attempts.json
|
data/login_attempts.json
|
||||||
data/backups/
|
data/backups/
|
||||||
data/files/
|
data/files/
|
||||||
|
data/companies.json
|
||||||
|
data/companies/*/
|
||||||
|
|||||||
20
api.php
20
api.php
@@ -138,6 +138,26 @@ function saveCompanyConfig(array $config): void {
|
|||||||
function runMigration(): void {
|
function runMigration(): void {
|
||||||
$companiesDir = DATA_DIR . '/companies';
|
$companiesDir = DATA_DIR . '/companies';
|
||||||
|
|
||||||
|
// Varmista companies.json olemassaolo (voi kadota git deploy:ssa)
|
||||||
|
if (!file_exists(COMPANIES_FILE)) {
|
||||||
|
// Jos cuitunet-hakemisto on olemassa, se on jo migrattu aiemmin → luo pelkkä companies.json
|
||||||
|
if (is_dir($companiesDir . '/cuitunet')) {
|
||||||
|
$companies = [[
|
||||||
|
'id' => 'cuitunet',
|
||||||
|
'nimi' => 'CuituNet',
|
||||||
|
'luotu' => date('Y-m-d H:i:s'),
|
||||||
|
'aktiivinen' => true,
|
||||||
|
]];
|
||||||
|
file_put_contents(COMPANIES_FILE, json_encode($companies, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Varmista yrityksen config.json (voi kadota git deploy:ssa)
|
||||||
|
$cuitunetConfig = $companiesDir . '/cuitunet/config.json';
|
||||||
|
if (is_dir($companiesDir . '/cuitunet') && !file_exists($cuitunetConfig)) {
|
||||||
|
file_put_contents($cuitunetConfig, json_encode(['mailboxes' => [], 'ticket_rules' => []], JSON_PRETTY_PRINT));
|
||||||
|
}
|
||||||
|
|
||||||
// Tarkista onko vanha data olemassa juuressa (pre-multitenant)
|
// Tarkista onko vanha data olemassa juuressa (pre-multitenant)
|
||||||
$oldCustomers = DATA_DIR . '/customers.json';
|
$oldCustomers = DATA_DIR . '/customers.json';
|
||||||
if (!file_exists($oldCustomers)) return; // Ei vanhaa dataa → ei migraatiota
|
if (!file_exists($oldCustomers)) return; // Ei vanhaa dataa → ei migraatiota
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"id": "cuitunet",
|
|
||||||
"nimi": "CuituNet",
|
|
||||||
"luotu": "2026-03-10 08:58:43",
|
|
||||||
"aktiivinen": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"mailboxes": [],
|
|
||||||
"ticket_rules": []
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user