This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
export class Migration20260626150000 extends Migration {
|
||||
|
||||
override async up(): Promise<void> {
|
||||
this.addSql(`DROP TRIGGER IF EXISTS trg_invoice_items_recalc ON invoice_items;`);
|
||||
this.addSql(`
|
||||
CREATE TRIGGER trg_invoice_items_recalc
|
||||
AFTER INSERT OR UPDATE OR DELETE
|
||||
ON invoice_items
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION recalc_invoice_totals();
|
||||
`);
|
||||
|
||||
this.addSql(`DROP TRIGGER IF EXISTS trg_payments_recalc ON payments;`);
|
||||
this.addSql(`
|
||||
CREATE TRIGGER trg_payments_recalc
|
||||
AFTER INSERT OR UPDATE OR DELETE
|
||||
ON payments
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION recalc_invoice_payments();
|
||||
`);
|
||||
|
||||
this.addSql(`
|
||||
UPDATE invoice_items
|
||||
SET quantity = quantity
|
||||
WHERE deleted_at IS NULL;
|
||||
`);
|
||||
}
|
||||
|
||||
override async down(): Promise<void> {
|
||||
this.addSql(`DROP TRIGGER IF EXISTS trg_invoice_items_recalc ON invoice_items;`);
|
||||
this.addSql(`DROP TRIGGER IF EXISTS trg_payments_recalc ON payments;`);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
"scripts": {
|
||||
"db:create": "npx mikro-orm schema:create --run --config ./src/config/mikro-orm.config.dev.ts",
|
||||
"db:update": "npx mikro-orm schema:update --run --config ./src/config/mikro-orm.config.dev.ts ",
|
||||
"db:drop": "npx mikro-orm schema:drop --run --config ./src/config/mikro-orm.config.dev.ts",
|
||||
"db:drop": "npx mikro-orm schema:drop --run --config ./src/config/mikro-orm.config.dev.ts && node scripts/db-drop-extras.js",
|
||||
"db:refresh": "npm run db:drop && npm run db:create ",
|
||||
"db:reset": "npm run db:drop && npm run db:create && npm run migration:up && npm run db:seed",
|
||||
"db:seed": "npx mikro-orm seeder:run --config ./src/config/mikro-orm.config.dev.ts",
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
require('dotenv').config();
|
||||
const { Client } = require('pg');
|
||||
|
||||
async function main() {
|
||||
const client = new Client({
|
||||
host: process.env.DB_HOST,
|
||||
port: process.env.DB_PORT,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASS,
|
||||
database: process.env.DB_NAME,
|
||||
});
|
||||
|
||||
await client.connect();
|
||||
|
||||
// schema:drop removes entity tables (and their triggers) but keeps these objects.
|
||||
await client.query('DROP TABLE IF EXISTS migrations CASCADE');
|
||||
await client.query('DROP FUNCTION IF EXISTS recalc_invoice_totals() CASCADE');
|
||||
await client.query('DROP FUNCTION IF EXISTS recalc_invoice_payments() CASCADE');
|
||||
|
||||
await client.end();
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user