Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94c16bc
commit c5d154c
Showing
15 changed files
with
254 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
language: node_js | ||
node_js: | ||
- '6' | ||
- '4' | ||
after_script: | ||
- 'cat coverage/lcov.info | ./node_modules/.bin/coveralls' | ||
addons: | ||
apt: | ||
packages: | ||
- oracle-java8-set-default | ||
services: | ||
- postgresql |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,67 @@ | ||
'use strict'; | ||
module.exports = (input, opts) => { | ||
if (typeof input !== 'string') { | ||
throw new TypeError(`Expected a string, got ${typeof input}`); | ||
const childProcess = require('child_process'); | ||
|
||
class Liquibase { | ||
constructor(params = {}) { | ||
this.liquibase = params.liquibase || process.env.NODE_LIQUIBASE || 'lib/liquibase-core-3.5.3.jar'; | ||
this.driver = params.driver || process.env.NODE_LIQUIBASE_DRIVER || 'org.postgresql.Driver'; | ||
this.classpath = params.classpath || process.env.NODE_LIQUIBASE_CLASSPATH || 'lib/postgresql-9.4-1201.jdbc4.jar'; | ||
|
||
this.changeLogFile = params.changeLogFile || process.env.NODE_LIQUIBASE_CHANGE_LOG_FILE; | ||
this.url = params.url || process.env.NODE_LIQUIBASE_URL; | ||
this.username = params.username || process.env.NODE_LIQUIBASE_USERNAME; | ||
this.password = params.password || process.env.NODE_LIQUIBASE_PASSWORD; | ||
|
||
this.defaultsFile = params.defaultsFile || process.env.NODE_LIQUIBASE_DEFAULTS_FILE; | ||
|
||
if (!this.defaultsFile) { | ||
if (!this.changeLogFile) { | ||
throw new Error('changeLogFile is undefined'); | ||
} | ||
if (!this.url) { | ||
throw new Error('url is undefined'); | ||
} | ||
if (!this.username) { | ||
throw new Error('username is undefined'); | ||
} | ||
} | ||
} | ||
|
||
opts = opts || {}; | ||
get command() { | ||
const cmd = `java -jar ${this.liquibase}`; | ||
|
||
if (this.defaultsFile) { | ||
return `${cmd} --defaultsFile=${this.defaultsFile}`; | ||
} | ||
|
||
return `${cmd}\ | ||
--driver=${this.driver}\ | ||
--classpath=${this.classpath}\ | ||
--changeLogFile=${this.changeLogFile}\ | ||
--url="${this.url}"\ | ||
--username=${this.username}\ | ||
--password=${this.password}\ | ||
`; | ||
} | ||
|
||
exec(command, options = {}) { | ||
let child; | ||
let promise = new Promise((resolve, reject) => { | ||
child = childProcess | ||
.exec(command, options, (error, stdout, stderr) => { | ||
if (error) { | ||
error.stderr = stderr; | ||
return reject(error); | ||
} | ||
resolve({stdout: stdout}); | ||
}); | ||
}); | ||
promise.child = child; | ||
return promise; | ||
} | ||
|
||
update() { | ||
return this.exec(`${this.command} update`); | ||
} | ||
} | ||
|
||
return input + ' & ' + (opts.postfix || 'rainbows'); | ||
}; | ||
module.exports = (params = {}) => new Liquibase(params); |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<databaseChangeLog | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9 | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"> | ||
|
||
<include file="resources/liquibase/release_1_0_0/001_create_test_table.sql"/> | ||
<include file="resources/liquibase/release_1_0_0/002_create_test_view.sql"/> | ||
</databaseChangeLog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<databaseChangeLog | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9 | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"> | ||
|
||
<include file="resources/liquibase/release_2_0_0/001_create_test_index.sql"/> | ||
</databaseChangeLog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9 | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"> | ||
|
||
<include file="resources/liquibase/db.changelog.release_1_0_0.xml"/> | ||
<include file="resources/liquibase/db.changelog.release_2_0_0.xml"/> | ||
</databaseChangeLog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
driver: org.postgresql.Driver | ||
classpath: lib/postgresql-9.4-1201.jdbc4.jar | ||
url: jdbc:postgresql://localhost:5432/postgres | ||
username: postgres | ||
password: admin | ||
changeLogFile: resources/liquibase/db.changelog.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--liquibase formatted sql | ||
--changeset liquibase-demo:release_1_0_0.001_create_test_table.sql | ||
|
||
CREATE TABLE liquibase_test ( | ||
key VARCHAR(64), | ||
value VARCHAR(255), | ||
PRIMARY KEY(key) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--liquibase formatted sql | ||
--changeset liquibase-demo:release_2_0_0.002_create_test_view.sql | ||
|
||
CREATE OR REPLACE VIEW | ||
liquibase_test_view AS select * from liquibase_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--liquibase formatted sql | ||
--changeset liquibase-demo:release_2_0_0.01_create_test_view.sql | ||
|
||
CREATE OR REPLACE VIEW | ||
liquibase_test_view AS select * from liquibase_test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,62 @@ | ||
import test from 'ava'; | ||
import fn from '.'; | ||
|
||
test('title', t => { | ||
const err = t.throws(() => fn(123), TypeError); | ||
t.is(err.message, 'Expected a string, got number'); | ||
test('constructor fail - no changeLogFile param or env variable', t => { | ||
const error = t.throws(fn); | ||
|
||
t.is(fn('unicorns'), 'unicorns & rainbows'); | ||
t.is(error.message, 'changeLogFile is undefined'); | ||
}); | ||
|
||
test('constructor fail - no url param or env variable', t => { | ||
const error = t.throws(() => { | ||
fn({ | ||
changeLogFile: 'resources/liquibase/db.changelog.xml' | ||
}); | ||
}); | ||
|
||
t.is(error.message, 'url is undefined'); | ||
}); | ||
|
||
test('constructor fail - no username param or env variable', t => { | ||
const error = t.throws(() => { | ||
fn({ | ||
changeLogFile: 'resources/liquibase/db.changelog.xml', | ||
url: 'jdbc:postgresql://localhost:5432/postgres' | ||
}); | ||
}); | ||
|
||
t.is(error.message, 'username is undefined'); | ||
}); | ||
|
||
test('update success - params', async t => { | ||
await fn({ | ||
changeLogFile: 'resources/liquibase/db.changelog.xml', | ||
url: 'jdbc:postgresql://localhost:5432/postgres', | ||
username: 'postgres', | ||
password: 'admin' | ||
}) | ||
.update() | ||
.then(data => t.is(data.stdout, '')) | ||
.catch(() => t.fail()); | ||
}); | ||
|
||
test('update success - defaults file', async t => { | ||
await fn({ | ||
defaultsFile: 'resources/liquibase/liquibase.properties' | ||
}) | ||
.update() | ||
.then(data => t.is(data.stdout, '')) | ||
.catch(() => t.fail()); | ||
}); | ||
|
||
test('update fail - params with wrong credentials', async t => { | ||
await fn({ | ||
changeLogFile: 'resources/liquibase/db.changelog.xml', | ||
url: 'jdbc:postgresql://localhost:5432/postgres', | ||
username: 'postgres!123', | ||
password: 'admin!123' | ||
}) | ||
.update() | ||
.then(() => t.fail()) | ||
.catch(() => t.pass()); | ||
}); |