Skip to content

Commit

Permalink
Drop Enums
Browse files Browse the repository at this point in the history
  • Loading branch information
cressie176 committed Jan 14, 2024
1 parent 11aa26d commit 4eec3ba
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/marv-filby-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const partials = {
addProjections: fs.readFileSync(path.join(__dirname, 'partials', 'add-projections.hbs'), 'utf-8'),
addHooks: fs.readFileSync(path.join(__dirname, 'partials', 'add-hooks.hbs'), 'utf-8'),
addChangeSets: fs.readFileSync(path.join(__dirname, 'partials', 'add-change-sets.hbs'), 'utf-8'),
dropEnums: fs.readFileSync(path.join(__dirname, 'partials', 'drop-enums.hbs'), 'utf-8'),
dropProjections: fs.readFileSync(path.join(__dirname, 'partials', 'drop-projections.hbs'), 'utf-8'),
dropHooks: fs.readFileSync(path.join(__dirname, 'partials', 'drop-hooks.hbs'), 'utf-8'),
};
Expand Down
5 changes: 5 additions & 0 deletions lib/partials/drop-enums.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{#if enums}}-- Drop Enums{{/if}}
{{#enums}}
DROP TYPE {{name}};

{{/enums}}
22 changes: 22 additions & 0 deletions lib/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
},
"drop_hooks": {
"$ref": "#/definitions/dropHooksType"
},
"drop enums": {
"$ref": "#/definitions/dropEnumsType"
},
"drop_enums": {
"$ref": "#/definitions/dropEnumsType"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -369,6 +375,22 @@
]
}
}
},
"dropEnumsType": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"name"
]
}
}
}
}
1 change: 1 addition & 0 deletions lib/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ START TRANSACTION;
{{> addChangeSets changeSets=add_change_sets}}
{{> dropProjections projections=drop_projections}}
{{> dropHooks hooks=drop_hooks}}
{{> dropEnums enums=drop_enums}}

END TRANSACTION;
41 changes: 41 additions & 0 deletions test/dsl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,47 @@ describe('DSL', () => {
});
});

describe('Drop Enums', () => {
it('should drop enums', async (t) => {
await applyYaml(t.name, `
add enums:
- name: vat_tax_rate
values:
- standard
- reduced
- zero
drop enums:
- name: vat_tax_rate
`);
await rejects(() => filby.withTransaction((tx) => tx.query("SELECT * FROM pg_enum WHERE enumtypid = 'vat_tax_rate'::regtype")), (err) => {
eq(err.code, '42704');
return true;
});
});

it('should require a name', async (t) => {
await rejects(() => applyYaml(t.name, `
drop enums:
- x: meh
`), (err) => {
match(err.message, new RegExp("^001.should-require-a-name.yaml: /drop_enums/0 must have required property 'name'$"));
return true;
});
});

it('should forbid additional properties', async (t) => {
await rejects(() => applyYaml(t.name, `
drop enums:
- name: vat_tax_rate
wombat: Freddy
`), (err) => {
match(err.message, new RegExp('^001.should-forbid-additional-properties.yaml: /drop_enums/0 must NOT have additional properties$'));
return true;
});
});
});

describe('Add Projections', () => {
it('should add projections', async (t) => {
await applyYaml(t.name, `
Expand Down

0 comments on commit 4eec3ba

Please sign in to comment.