Added the paidOff the sharesEven columns to the database

This commit is contained in:
2025-08-13 14:14:06 +01:00
parent d451bc6e70
commit 300ee481e3
3 changed files with 32 additions and 1 deletions
@@ -0,0 +1,4 @@
-- 0003_add_paidOff_column.down.sql
ALTER TABLE expenses DROP COLUMN "PaidOff";
ALTER TABLE expenses DROP COLUMN "SharesEven";
@@ -0,0 +1,27 @@
-- 0003_add_paidOff_column.up.sql
ALTER TABLE expenses ADD COLUMN "PaidOff" BOOL DEFAULT FALSE;
ALTER TABLE expenses ADD COLUMN "SharesEven" BOOL DEFAULT FALSE;
-- Update the SharesEven column
UPDATE expenses
SET SharesEven = TRUE
WHERE ExpID IN (
SELECT e.ExpID
FROM expenses e
JOIN expensesPayments p ON p.ExpID = e.ExpID
GROUP BY e.ExpID
HAVING ROUND(SUM(CAST(p.Payed AS REAL)), 2) == e.Value
);
-- Update the PaidOff column
UPDATE expenses
SET "PaidOff" = TRUE
WHERE ExpID IN (
SELECT p.ExpID as ExpID
FROM expensesPayments AS p
JOIN expenses as e
ON e.ExpID = p.ExpID
GROUP BY p.ExpId
HAVING ROUND(CAST(e.Value AS REAL),2) == ROUND(SUM(CAST(p.Payed AS REAL)), 2)
);
+1 -1
View File
@@ -47,7 +47,7 @@ func RunMigrations(db *sql.DB) error {
} }
if dirty, ok := err.(mig.ErrDirty); ok { if dirty, ok := err.(mig.ErrDirty); ok {
log.Printf("migration %d is dirty:", dirty.Version) log.Printf("migration %d is dirty:", err)
forceErr := m.Force(int(dirty.Version - 1)) forceErr := m.Force(int(dirty.Version - 1))
if forceErr != nil { if forceErr != nil {