mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
Add a script that generates a liquibase changelog. Should be internal.
This commit is contained in:
parent
e4b31d5570
commit
5a670e8bea
@ -1,7 +1,7 @@
|
||||
# unleash-server
|
||||
unleash-server is a place to ask for the status of features.
|
||||
|
||||
# Important commands:
|
||||
## Important commands:
|
||||
|
||||
```
|
||||
// Set up DB
|
||||
@ -20,3 +20,11 @@ http://localhost:4242/features
|
||||
// Execute tests:
|
||||
npm test
|
||||
```
|
||||
|
||||
## Making a schema change
|
||||
|
||||
1. Create `migrations/sql/NNN-your-migration-name.up.sql` with your change in SQL.
|
||||
2. Create `migrations/sql/NNN-your-migration-name.down.sql` with the rollback of your change in SQL.
|
||||
3. Run `db-migrate create your-migration-name` and edit the generated file to run the above SQL files.
|
||||
4. Run `npm run db-migrate-up`.
|
||||
5. Generate LB artifact using `scripts/generate-liquibase-artifact` (TODO: make this internal)
|
||||
|
@ -45,6 +45,7 @@
|
||||
"jshint": "2.5.2",
|
||||
"mocha": "1.20.1",
|
||||
"supertest": "0.13.0",
|
||||
"supervisor": "~0.6.0"
|
||||
"supervisor": "~0.6.0",
|
||||
"xmlbuilder": "^2.4.4"
|
||||
}
|
||||
}
|
||||
|
51
unleash-server/scripts/generate-liquibase-artifact.js
Executable file
51
unleash-server/scripts/generate-liquibase-artifact.js
Executable file
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// TODO: move this to somewhere internal
|
||||
|
||||
var builder = require('xmlbuilder');
|
||||
var util = require('util');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var sqlRoot = path.resolve(__dirname, '../migrations/sql');
|
||||
var encoding = 'UTF-8';
|
||||
|
||||
var changeLog = builder.create('databaseChangeLog').dec('1.0', encoding);
|
||||
changeLog.att('xmlns', 'http://www.liquibase.org/xml/ns/dbchangelog');
|
||||
changeLog.att('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
|
||||
changeLog.att('xmlns:ext', 'http://www.liquibase.org/xml/ns/dbchangelog-ext');
|
||||
changeLog.att('xsi:schemaLocation',
|
||||
'http://www.liquibase.org/xml/ns/dbchangelog ' +
|
||||
'http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd ' +
|
||||
'http://www.liquibase.org/xml/ns/dbchangelog-ext ' +
|
||||
'http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd');
|
||||
|
||||
fs.readdir(sqlRoot, function (err, files) {
|
||||
if (err) { throw err; }
|
||||
|
||||
var changes = {};
|
||||
|
||||
files.forEach(function (sqlFile) {
|
||||
var match = sqlFile.match(/(.+?)\.(up|down)\.sql/);
|
||||
|
||||
if (!match) {
|
||||
throw util.format('invalid sql file name, missing up|down: %s', sqlFile);
|
||||
}
|
||||
|
||||
var name = match[1];
|
||||
var direction = match[2];
|
||||
|
||||
changes[name] = changes[name] || {};
|
||||
changes[name][direction] = fs.readFileSync(path.resolve(sqlRoot, sqlFile), {encoding: encoding});
|
||||
});
|
||||
|
||||
Object.keys(changes).forEach(function (name) {
|
||||
var change = changes[name];
|
||||
|
||||
var el = changeLog.ele('changeSet', {id: name});
|
||||
el.ele('sql', {}, change.up);
|
||||
el.ele('rollback', {}, change.down);
|
||||
});
|
||||
|
||||
util.puts(changeLog.end({pretty: true}));
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user