Skip to content

Commit 7350016

Browse files
author
MIYASHITA, Akihiro
committed
Change PostgreSQL initialization code as well as MySQL code
1 parent f286a6e commit 7350016

File tree

3 files changed

+8
-60
lines changed

3 files changed

+8
-60
lines changed

lib/connection.js

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -141,69 +141,17 @@ class SQLiteCasette {
141141

142142
class PostgreSQLCasette {
143143
async newConnection(options) {
144-
async function startServer() {
145-
return new Promise((_res, _rej) => {
146-
let done = false;
147-
const res = (...args) => {
148-
if (!done) {
149-
done = true;
150-
_res(...args);
151-
}
152-
}
153-
const rej = (...args) => {
154-
if (!done) {
155-
done = true;
156-
_rej(...args);
157-
}
158-
}
159-
sleep(10000).then(() => rej(new Error('Timeout database connection')));
160-
const p = cp.spawn('docker-entrypoint.sh', ['postgres'], {
161-
detached: true,
162-
});
163-
p.stdout.on('data', data => {
164-
const message = data.toString();
165-
if (options.verbose) {
166-
console.log(message);
167-
}
168-
if (message.includes('database system is ready to accept connections')) {
169-
res();
170-
}
171-
});
172-
p.stderr.on('data', data => {
173-
const message = data.toString();
174-
if (options.verbose) {
175-
console.error(message);
176-
}
177-
if (message.includes('database system is ready to accept connections')) {
178-
res();
179-
}
180-
});
181-
});
182-
}
183-
184-
if (!fs.existsSync('/var/run/postgresql/.s.PGSQL.5432')) {
185-
for (let retries = 5; retries > 0; retries--) {
186-
try {
187-
await startServer();
188-
break;
189-
} catch (e) {
190-
if (options.verbose) {
191-
console.error(e);
192-
}
193-
}
194-
await sleep(1000);
195-
}
196-
}
197-
198-
for (let retries = 20; retries > 0; retries--) {
144+
for (let retries = 10; retries > 0; retries--) {
199145
try {
146+
await exec('service postgresql start');
200147
const conn = knex({
201148
client: 'pg',
202149
connection: {
203150
host: '127.0.0.1',
204-
user: 'postgres',
205-
database: 'postgres',
151+
port: 5432,
152+
user: 'track',
206153
password: 'password',
154+
database: 'track',
207155
},
208156
});
209157
await conn.raw("SELECT 1");

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "track-db-test-library",
3-
"version": "2.6.0-rc5",
3+
"version": "2.6.0-rc6",
44
"description": "Test utility for Track database challenges",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)