sqitchers / sqitch

Sensible database change management

Home Page:https://sqitch.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Per-Engine Custom Templates

theory opened this issue · comments

#795 highlighted some issues with template resolution. The fix in #796 addresses the issue sufficiently for adding changes to multiple engines at once, but only if not using a custom template. The current design limits custom templates to a single engine -- a limitation dating from when add supported only one engine at a time (changed in way back in 0c7237c).

So do some re-thinking and re-organization of templates in order to better support both multiple engines and custom templates for multiple engines.

Here's what it looks like today:

etc/templates
├── deploy
│   ├── mysql.tmpl
│   ├── pg.tmpl
│   ├── sqlite.tmpl
├── revert
│   ├── mysql.tmpl
│   ├── pg.tmpl
│   ├── sqlite.tmpl
└── verify
    ├── mysql.tmpl
    ├── pg.tmpl
    └── sqlite.tmpl

Which is fine for a single template for each engine. Say we wanted to add a custom change, named create_table, with separate templates for the pg and sqlite engines. Currently it requires a structure like this:

etc/templates
├── deploy
│   ├── mysql.tmpl
│   ├── pg.tmpl
│   ├── sqlite.tmpl
├── revert
│   ├── mysql.tmpl
│   ├── pg.tmpl
│   ├── sqlite.tmpl
└── verify
    ├── mysql.tmpl
    ├── pg.tmpl
    └── sqlite.tmpl

But what engine does it apply to? In order to support the same template for multiple engines, add support for engine-specific subdirectories, so we can do this, instead:

etc/templates
├── deploy
│   ├── mysql.tmpl
│   ├── pg
│   │   └── create_table.tmpl
│   ├── pg.tmpl
│   ├── sqlite
│   │   └── create_table.tmpl
│   └── sqlite.tmpl
├── revert
│   ├── mysql.tmpl
│   ├── pg
│   │   └── create_table.tmpl
│   ├── pg.tmpl
│   ├── sqlite
│   │   └── create_table.tmpl
│   └── sqlite.tmpl
└── verify
    ├── mysql.tmpl
    ├── pg
    │   └── create_table.tmpl
    ├── pg.tmpl
    ├── sqlite
    │   └── create_table.tmpl
    └── sqlite.tmpl

The defaults for each engine remain as they are, as do custom templates that can be the same across engines (or are only ever used for one). But adding this level allows for more customization.