diff --git a/examples/migrations/0001.define-park-schema.yaml b/examples/migrations/0001.define-park-schema.yaml index 990fe44..a998558 100644 --- a/examples/migrations/0001.define-park-schema.yaml +++ b/examples/migrations/0001.define-park-schema.yaml @@ -1,5 +1,4 @@ define enums: - - name: park_calendar_event_type values: - Park Open - Owners @@ -8,7 +7,6 @@ define enums: - Park Close - Guests define entities: - - name: park version: 1 fields: @@ -39,10 +37,10 @@ add projections: - name: park version: 1 dependencies: - - name: park - version: 1 - - name: park_calendar - version: 1 + - name: park + version: 1 + - name: park_calendar + version: 1 add hooks: - projection: park diff --git a/index.js b/index.js index dd31a22..a3b4a8a 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,7 @@ module.exports = class ReferenceDataFramework extends EventEmitter { async #migrate(connection, directory) { const migrations = await marv.scan(directory); - return marv.migrate(migrations, driver({ connection })); + await marv.migrate(migrations, driver({ connection })); } async startNotifications() { diff --git a/lib/marv-rdf-driver.js b/lib/marv-rdf-driver.js index 7772135..5fa0da7 100644 --- a/lib/marv-rdf-driver.js +++ b/lib/marv-rdf-driver.js @@ -1,14 +1,21 @@ -const fs = require('fs'); -const path = require('path'); +const fs = require('node:fs'); +const path = require('node:path'); + +const Ajv = require('ajv'); +const addFormats = require("ajv-formats") const YAML = require('yaml'); const Handlebars = require('handlebars'); const marvPgDriver = require('marv-pg-driver'); +const schema = require('./schema'); const proxy = require('./proxy'); const helpers = require('./helpers'); -const templateSource = fs.readFileSync(path.join(__dirname, 'template.hbs'), 'utf-8'); -const template = Handlebars.compile(templateSource); +const template = fs.readFileSync(path.join(__dirname, 'template.hbs'), 'utf-8'); +const render = Handlebars.compile(template); +const ajv = new Ajv(); +addFormats(ajv); +const validate = ajv.compile(schema); Handlebars.registerHelper(helpers); @@ -18,13 +25,15 @@ module.exports = (options) => { function runMigration(migration, cb) { const fileType = getFileType(migration); - if (fileType === 'sql') return pgDriver.runMigration(migration, cb); const script = parseMigrationScript(migration, fileType); + if (!validate(script)) throw createValidationError(validate); + decorateMigrationScript(script); - pgDriver.runMigration({ ...migration, script: template(script) }, cb); + const sql = render(script) + pgDriver.runMigration({ ...migration, script: sql }, cb); } function getFileType(migration) { @@ -47,6 +56,24 @@ module.exports = (options) => { } }; + function createValidationError(validate) { + let message; + const errors = validate.errors.filter((e => e.keyword !== 'oneOf')); + const instancePath = errors[0].instancePath || 'migration script'; + switch (errors[0].keyword) { + case 'required': { + const missingProperties = errors.map(e => `'${e.params.missingProperty}'`).join(' or '); + message = `${instancePath} must have required property ${missingProperties}`; + break; + } + default: { + message = `${instancePath} ${errors[0].message.replace(/be object/, 'be an object')}`; + break; + } + } + return new Error(message); + } + function decorateMigrationScript(script) { script.define_entities?.forEach((entity) => { entity.table_name = entity.name.toLowerCase().replace(/\s/g, '_'); diff --git a/lib/schema.json b/lib/schema.json new file mode 100644 index 0000000..49e8c9f --- /dev/null +++ b/lib/schema.json @@ -0,0 +1,263 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "JSON Schema for RDF", + "type": "object", + "properties": { + "define enums": { + "$ref": "#/definitions/enumsType" + }, + "define_enums": { + "$ref": "#/definitions/enumsType" + }, + "define entities": { + "$ref": "#/definitions/entitiesType" + }, + "define_entities": { + "$ref": "#/definitions/entitiesType" + }, + "add projections": { + "$ref": "#/definitions/projectionsType" + }, + "add_projections": { + "$ref": "#/definitions/projectionsType" + }, + "add hooks": { + "$ref": "#/definitions/hooksType" + }, + "add_hooks": { + "$ref": "#/definitions/hooksType" + }, + "add change set": { + "$ref": "#/definitions/changeSetType" + }, + "add_change_set": { + "$ref": "#/definitions/changeSetType" + } + }, + "definitions": { + "enumsType": { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "values": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "name", + "values" + ] + } + }, + "entitiesType": { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "integer" + }, + "fields": { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "type": { + "type": "string" + } + }, + "required": [ + "name", + "type" + ] + } + }, + "identified by": { + "type": "array", + "minItems": 1, + "items": { + "type": "string" + } + }, + "checks": { + "type": "object", + "minProperties": 1, + "patternProperties": { + ".+": { + "type": "string" + } + } + } + }, + "oneOf": [ + { + "required": [ + "name", + "version", + "fields", + "identified by" + ] + }, + { + "required": [ + "name", + "version", + "fields", + "identified_by" + ] + } + ] + } + }, + "projectionsType": { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "integer" + }, + "dependencies": { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "properties": { + "entity": { + "type": "string" + }, + "version": { + "type": "integer" + } + }, + "required": [ + "entity", + "version" + ] + } + } + }, + "required": [ + "name", + "version", + "dependencies" + ] + } + }, + "hooksType": { + "type": "array", + "items": { + "type": "object", + "properties": { + "projection": { + "type": "string" + }, + "version": { + "type": "integer" + }, + "event": { + "type": "string" + } + }, + "oneOf": [ + { + "required": [ + "projection", + "version", + "event" + ] + }, + { + "required": [ + "event" + ] + } + ] + } + }, + "changeSetType": { + "type": "object", + "properties": { + "effective_from": { + "type": "string", + "format": "date-time" + }, + "notes": { + "type": "string" + }, + "frames": { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "properties": { + "entity": { + "type": "string" + }, + "version": { + "type": "integer" + }, + "action": { + "type": "string", + "enum": [ + "POST", + "DELETE" + ] + }, + "data": { + "type": "array", + "minItems": 1, + "items": { + "type": "object" + } + } + }, + "required": [ + "entity", + "version", + "action", + "data" + ] + } + } + }, + "oneOf": [ + { + "required": [ + "effective_from", + "notes", + "frames" + ] + }, + { + "required": [ + "effective from", + "notes", + "frames" + ] + } + ] + } + }, + "required": [] +} \ No newline at end of file diff --git a/lib/template.hbs b/lib/template.hbs index b7ec953..b555954 100644 --- a/lib/template.hbs +++ b/lib/template.hbs @@ -70,11 +70,11 @@ DECLARE BEGIN INSERT INTO rdf_projection (name, version) VALUES - ('{{name}}', {{version}}){{#unless @last}}),{{/unless}} + ('{{name}}', {{version}}) RETURNING id INTO v_projection_id; {{#dependencies}} - SELECT id INTO v_entity_id FROM rdf_entity WHERE name = '{{name}}' AND version = {{version}}; + SELECT id INTO v_entity_id FROM rdf_entity WHERE name = '{{entity}}' AND version = {{version}}; INSERT INTO rdf_projection_entity (projection_id, entity_id) VALUES (v_projection_id, v_entity_id); diff --git a/package-lock.json b/package-lock.json index 2872d2a..60332ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,8 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "ajv": "^8.12.0", + "ajv-formats": "^2.1.1", "eventemitter2": "^6.4.9", "handlebars": "^4.7.8", "marv": "^6.0.0", @@ -506,6 +508,37 @@ "node": ">=8" } }, + "node_modules/ajv": { + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", + "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", + "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, "node_modules/ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", @@ -844,6 +877,11 @@ "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-6.4.9.tgz", "integrity": "sha512-JEPTiaOt9f04oa6NOkc4aH+nVp5I3wEjpHbIPqfgCdD5v5bUzy7xQqwcVO2aDQgOWhI28da57HksMrzK9HlRxg==" }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" + }, "node_modules/find-cache-dir": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.2.tgz", @@ -1301,6 +1339,11 @@ "node": ">=4" } }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" + }, "node_modules/json5": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", @@ -1776,6 +1819,14 @@ "node": ">=8" } }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "engines": { + "node": ">=6" + } + }, "node_modules/regenerator-runtime": { "version": "0.14.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", @@ -1802,6 +1853,14 @@ "node": ">=0.10.0" } }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/require-main-filename": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", @@ -2049,6 +2108,14 @@ "browserslist": ">= 4.21.0" } }, + "node_modules/uri-js": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dependencies": { + "punycode": "^2.1.0" + } + }, "node_modules/uuid": { "version": "8.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", @@ -2607,6 +2674,25 @@ "indent-string": "^4.0.0" } }, + "ajv": { + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", + "integrity": "sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==", + "requires": { + "fast-deep-equal": "^3.1.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2", + "uri-js": "^4.2.2" + } + }, + "ajv-formats": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", + "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", + "requires": { + "ajv": "^8.0.0" + } + }, "ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", @@ -2849,6 +2935,11 @@ "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-6.4.9.tgz", "integrity": "sha512-JEPTiaOt9f04oa6NOkc4aH+nVp5I3wEjpHbIPqfgCdD5v5bUzy7xQqwcVO2aDQgOWhI28da57HksMrzK9HlRxg==" }, + "fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" + }, "find-cache-dir": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.2.tgz", @@ -3178,6 +3269,11 @@ "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", "dev": true }, + "json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" + }, "json5": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", @@ -3544,6 +3640,11 @@ "fromentries": "^1.2.0" } }, + "punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==" + }, "regenerator-runtime": { "version": "0.14.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", @@ -3564,6 +3665,11 @@ "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", "dev": true }, + "require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==" + }, "require-main-filename": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", @@ -3737,6 +3843,14 @@ "picocolors": "^1.0.0" } }, + "uri-js": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "requires": { + "punycode": "^2.1.0" + } + }, "uuid": { "version": "8.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", diff --git a/package.json b/package.json index 0288d84..3ca30c1 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,8 @@ "coverage": "nyc --report html --reporter lcov --reporter text-summary zUnit" }, "dependencies": { + "ajv": "^8.12.0", + "ajv-formats": "^2.1.1", "eventemitter2": "^6.4.9", "handlebars": "^4.7.8", "marv": "^6.0.0", diff --git a/test/TestReferenceDataFramework.js b/test/TestReferenceDataFramework.js index 1cc45d6..0eae180 100644 --- a/test/TestReferenceDataFramework.js +++ b/test/TestReferenceDataFramework.js @@ -1,16 +1,38 @@ const ReferenceDataFramework = require('..'); module.exports = class TestReferenceDataFramework extends ReferenceDataFramework { + + #nukeCustomObjects; + #wipeCustomData; + + constructor(config) { + super(config); + this.#nukeCustomObjects = config.nukeCustomObjects; + this.#wipeCustomData = config.wipeCustomData; + } + + async reset() { + await this.withTransaction(async (tx) => { + await this.#nukeCustomObjects(tx); + await this.#wipeRdfData(tx); + }) + await this.init(); + } + async wipe() { await this.withTransaction(async (tx) => { - await tx.query('DELETE FROM vat_rate_v1'); - await tx.query('DELETE FROM rdf_notification'); - await tx.query('DELETE FROM rdf_hook'); - await tx.query('DELETE FROM rdf_data_frame'); - await tx.query('DELETE FROM rdf_projection_entity'); - await tx.query('DELETE FROM rdf_entity'); - await tx.query('DELETE FROM rdf_change_set'); - await tx.query('DELETE FROM rdf_projection'); - }); + await this.#wipeCustomData(tx); + await this.#wipeRdfData(tx); + }) + } + + async #wipeRdfData(tx) { + await tx.query('DELETE FROM rdf_notification'); + await tx.query('DELETE FROM rdf_hook'); + await tx.query('DELETE FROM rdf_data_frame'); + await tx.query('DELETE FROM rdf_projection_entity'); + await tx.query('DELETE FROM rdf_entity'); + await tx.query('DELETE FROM rdf_change_set'); + await tx.query('DELETE FROM rdf_projection'); } } \ No newline at end of file diff --git a/test/dsl.test.js b/test/dsl.test.js new file mode 100644 index 0000000..464b11e --- /dev/null +++ b/test/dsl.test.js @@ -0,0 +1,120 @@ +const fs = require('node:fs'); +const path = require('node:path'); +const { ok, strictEqual: eq, deepEqual: deq, rejects, match } = require('node:assert'); +const { describe, it, before, beforeEach, after, afterEach } = require('zunit'); + +const TestReferenceDataFramework = require('./TestReferenceDataFramework'); + +const config = { + migrations: 'test/dsl', + database: { + user: 'rdf_test', + password: 'rdf_test' + }, + notifications: { + initialDelay: '0ms', + interval: '100ms', + maxAttempts: 3, + maxRescheduleDelay: '100ms', + }, + nukeCustomObjects: async (tx) => { + await tx.query('DROP TABLE IF EXISTS vat_rate_v1'); + await tx.query('DROP FUNCTION IF EXISTS get_vat_rate_v1_aggregate'); + await tx.query('DROP TABLE IF EXISTS vat_rate_v2'); + await tx.query('DROP FUNCTION IF EXISTS get_vat_rate_v2_aggregate'); + await tx.query('DROP TABLE IF EXISTS cgt_rate_v1'); + await tx.query('DROP FUNCTION IF EXISTS get_cgt_rate_v1_aggregate'); + }, + wipeCustomData: async (tx) => { + await tx.query('DELETE FROM vat_rate_v1'); + await tx.query('DELETE FROM vat_rate_v2'); + await tx.query('DELETE FROM cgt_rate_v1'); + } +} + +describe('DSL', () => { + + let rdf; + + before(async () => { + rdf = new TestReferenceDataFramework(config); + await rdf.reset(); + }) + + beforeEach(async () => { + deleteMigrations(); + await rdf.reset(); + }) + + after(async () => { + await rdf.stop(); + }) + + describe('Projections', () => { + it('should add projections', async (t) => { + await apply(t.name, ` + define entities: + - name: VAT Rate + version: 1 + fields: + - name: type + type: TEXT + - name: rate + type: NUMERIC + identified by: + - type + + add projections: + - name: VAT Rates + version: 1 + dependencies: + - entity: VAT Rate + version: 1 + `); + const { rows: projections } = await rdf.withTransaction((tx) => { + return tx.query('SELECT name, version FROM rdf_projection'); + }); + + eq(projections.length, 1); + deq(projections[0], { name: 'VAT Rates', version: 1 }); + }); + }); + + describe('Entities', () => { + it('should add entities', async (t) => { + await apply(t.name, ` + define entities: + - name: VAT Rate + version: 1 + fields: + - name: type + type: TEXT + - name: rate + type: NUMERIC + identified by: [ + type + ] + `); + + const { rows: entities } = await rdf.withTransaction((tx) => { + return tx.query('SELECT name, version FROM rdf_entity'); + }); + + eq(entities.length, 1); + deq(entities[0], { name: 'VAT Rate', version: 1 }); + }); + }); + + async function apply(name, script) { + fs.writeFileSync(path.join(__dirname, 'dsl', `001.${name.replace(/ /g, '-')}.yaml`), script, { encoding: 'utf-8' }); + await rdf.init(); + } + + function deleteMigrations() { + fs.readdirSync(path.join(__dirname, 'dsl')) + .filter(file => path.extname(file).toLowerCase() === '.yaml') + .map(file => path.join(__dirname, 'dsl', file)) + .forEach(file => fs.unlinkSync(file)); + } + +}); diff --git a/test/dsl/.gitignore b/test/dsl/.gitignore new file mode 100644 index 0000000..2a61605 --- /dev/null +++ b/test/dsl/.gitignore @@ -0,0 +1 @@ +*.yaml \ No newline at end of file diff --git a/test/dsl/.marvrc b/test/dsl/.marvrc new file mode 100644 index 0000000..49b0f7e --- /dev/null +++ b/test/dsl/.marvrc @@ -0,0 +1,7 @@ +{ + "namespace": "dsl", + "filter": "(?:\\.sql|\\.yaml|\\.json)$", + "directives": { + "audit": false + } +} \ No newline at end of file diff --git a/test/index.test.js b/test/index.test.js index 0ef7c7d..ac19e3b 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -4,7 +4,7 @@ const { describe, it, before, beforeEach, after, afterEach } = require('zunit'); const TestReferenceDataFramework = require('./TestReferenceDataFramework'); const config = { - migrations: 'test/dsl', + migrations: 'test/migrations', database: { user: 'rdf_test', password: 'rdf_test' @@ -14,6 +14,14 @@ const config = { interval: '100ms', maxAttempts: 3, maxRescheduleDelay: '100ms', + }, + nukeCustomObjects: async (tx) => { + await tx.query('DROP TABLE IF EXISTS vat_rate_v1'); + await tx.query('DROP FUNCTION IF EXISTS get_vat_rate_v1_aggregate'); + await tx.query('DROP TYPE IF EXISTS tax_rate_type'); + }, + wipeCustomData: async (tx) => { + await tx.query('DELETE FROM vat_rate_v1'); } } @@ -23,7 +31,7 @@ describe('RDF', () => { before(async () => { rdf = new TestReferenceDataFramework(config); - await rdf.init(); + await rdf.reset(); }) beforeEach(async () => { diff --git a/test/migrations/.marvrc b/test/migrations/.marvrc index 432865a..8ea3ed5 100644 --- a/test/migrations/.marvrc +++ b/test/migrations/.marvrc @@ -1,3 +1,6 @@ { - "filter": "(?:\\.sql|\\.yaml|\\.json)$" -} + "filter": "(?:\\.sql|\\.yaml|\\.json)$", + "directives": { + "audit": false + } +} \ No newline at end of file