This commit is contained in:
seb
2026-10-24 01:24:25 +02:00
parent feffe4e1ab
commit 1da82e2eb9
7 changed files with 20 additions and 2 deletions

View File

@@ -199,6 +199,11 @@ export class MssqlProvider {
ALTER TABLE category ADD updated_at DATETIME2 NOT NULL CONSTRAINT DF_category_updated_at DEFAULT SYSUTCDATETIME();
END
IF OBJECT_ID(N'dbo.payment', N'U') IS NOT NULL AND COL_LENGTH('payment', 'created_at') IS NULL
BEGIN
ALTER TABLE payment ADD created_at DATETIME2 NOT NULL CONSTRAINT DF_payment_created_at DEFAULT SYSUTCDATETIME();
END
IF OBJECT_ID(N'dbo.customergroup', N'U') IS NOT NULL AND COL_LENGTH('customergroup', 'updated_at') IS NULL
BEGIN
ALTER TABLE customergroup ADD updated_at DATETIME2 NOT NULL CONSTRAINT DF_customergroup_updated_at DEFAULT SYSUTCDATETIME();

View File

@@ -39,12 +39,12 @@ WHERE id = @id AND company_id = @companyId
export const PAYMENT_CREATE = `
INSERT INTO payment (account_id, manifest_id, [type], amount)
OUTPUT INSERTED.id, INSERTED.account_id, INSERTED.manifest_id, INSERTED.[type], INSERTED.amount
OUTPUT INSERTED.id, INSERTED.account_id, INSERTED.manifest_id, INSERTED.[type], INSERTED.amount, INSERTED.created_at AS createdAt
VALUES (@accountId, @manifestId, @type, @amount)
`;
export const PAYMENT_LIST_BY_MANIFEST = `
SELECT id, account_id, manifest_id, [type], amount
SELECT id, account_id, manifest_id, [type], amount, created_at AS createdAt
FROM payment
WHERE manifest_id = @manifestId
ORDER BY id ASC

View File

@@ -1141,6 +1141,7 @@ BEGIN
manifest_id INT NOT NULL,
[type] NVARCHAR(100) NOT NULL,
amount FLOAT NOT NULL,
created_at DATETIME2 NOT NULL CONSTRAINT DF_payment_created_at DEFAULT SYSUTCDATETIME(),
CONSTRAINT FK_payment_account FOREIGN KEY (account_id) REFERENCES account(id) ON DELETE CASCADE,
CONSTRAINT FK_payment_manifest FOREIGN KEY (manifest_id) REFERENCES manifest(id) ON DELETE CASCADE
);

View File

@@ -494,6 +494,13 @@ export class BetterSqlite3Provider extends BetterSqlite3Executor {
this.db.exec(`UPDATE category SET updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now') WHERE updated_at IS NULL`);
}
const paymentCols = this.db.pragma('table_info("payment")').map((c) => c.name);
if (paymentCols.length > 0 && !paymentCols.includes('created_at')) {
this.db.exec('ALTER TABLE payment ADD COLUMN created_at TEXT');
this.db.exec('UPDATE payment SET created_at = (SELECT m.created_at FROM manifest m WHERE m.id = payment.manifest_id) WHERE EXISTS (SELECT 1 FROM manifest m WHERE m.id = payment.manifest_id)');
this.db.exec('UPDATE payment SET created_at = strftime("%Y-%m-%dT%H:%M:%fZ", "now") WHERE created_at IS NULL');
}
const customergroupCols = this.db.pragma('table_info("customergroup")').map((c) => c.name);
if (customergroupCols.length > 0 && !customergroupCols.includes('updated_at')) {
this.db.exec(`ALTER TABLE customergroup ADD COLUMN updated_at TEXT`);

View File

@@ -813,6 +813,7 @@ CREATE TABLE IF NOT EXISTS payment (
manifest_id INTEGER NOT NULL,
"type" TEXT NOT NULL,
amount REAL NOT NULL,
created_at TEXT NOT NULL DEFAULT (${UTC_NOW}),
FOREIGN KEY (account_id) REFERENCES account(id) ON DELETE CASCADE,
FOREIGN KEY (manifest_id) REFERENCES manifest(id) ON DELETE CASCADE
);

View File

@@ -11,6 +11,8 @@ function shape(row) {
manifestId: row.manifest_id,
type: row.type,
amount: row.amount,
createdAt: row.createdAt ?? row.created_at ?? null,
date: row.date ?? row.createdAt ?? row.created_at ?? null,
};
}

View File

@@ -32,6 +32,8 @@ export default function listByManifestId(provider) {
manifestId: row.manifest_id,
type: row.type,
amount: row.amount,
createdAt: row.createdAt ?? row.created_at ?? null,
date: row.date ?? row.createdAt ?? row.created_at ?? null,
}));
};
}