feat(F-185): completed feature
This commit is contained in:
10
project/migrations/052_reporting_payment_currency_default.js
Normal file
10
project/migrations/052_reporting_payment_currency_default.js
Normal file
@@ -0,0 +1,10 @@
|
||||
/** @param {import('node-pg-migrate').MigrationBuilder} pgm */
|
||||
exports.shorthands = undefined;
|
||||
|
||||
exports.up = (pgm) => {
|
||||
pgm.sql(`ALTER TABLE reporting_payment_lines ALTER COLUMN currency SET DEFAULT 'EUR';`);
|
||||
};
|
||||
|
||||
exports.down = (pgm) => {
|
||||
pgm.sql(`ALTER TABLE reporting_payment_lines ALTER COLUMN currency SET DEFAULT '''EUR''';`);
|
||||
};
|
||||
28
project/migrations/053_reporting_payment_line_checks.js
Normal file
28
project/migrations/053_reporting_payment_line_checks.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/** @param {import('node-pg-migrate').MigrationBuilder} pgm */
|
||||
exports.shorthands = undefined;
|
||||
|
||||
exports.up = (pgm) => {
|
||||
pgm.sql(`
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'reporting_payment_lines_eur_only') THEN
|
||||
ALTER TABLE reporting_payment_lines
|
||||
ADD CONSTRAINT reporting_payment_lines_eur_only CHECK (currency = 'EUR');
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'reporting_payment_lines_valid_status') THEN
|
||||
ALTER TABLE reporting_payment_lines
|
||||
ADD CONSTRAINT reporting_payment_lines_valid_status
|
||||
CHECK (status IN ('payment', 'refund', 'partial_refund'));
|
||||
END IF;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
`);
|
||||
};
|
||||
|
||||
exports.down = (pgm) => {
|
||||
pgm.sql(`
|
||||
ALTER TABLE reporting_payment_lines
|
||||
DROP CONSTRAINT IF EXISTS reporting_payment_lines_valid_status,
|
||||
DROP CONSTRAINT IF EXISTS reporting_payment_lines_eur_only;
|
||||
`);
|
||||
};
|
||||
Reference in New Issue
Block a user