2019-09-12 15:26:21 +00:00
|
|
|
import * as fs from 'fs';
|
2022-08-17 23:35:08 +00:00
|
|
|
import * as db from '~/src/db';
|
|
|
|
import * as config from '~/src/config';
|
2019-09-12 15:26:21 +00:00
|
|
|
|
2020-05-28 17:15:33 +00:00
|
|
|
export = async function () {
|
2022-09-06 18:03:23 +00:00
|
|
|
await db.initialized();
|
|
|
|
await config.initialized();
|
2020-06-02 13:29:05 +00:00
|
|
|
|
2020-05-28 17:15:33 +00:00
|
|
|
await db.transaction(async (trx) => {
|
|
|
|
const result = await trx.raw(`
|
|
|
|
SELECT name, sql
|
|
|
|
FROM sqlite_master
|
|
|
|
WHERE type='table'`);
|
|
|
|
for (const r of result) {
|
|
|
|
// We don't run the migrations again
|
|
|
|
if (r.name !== 'knex_migrations') {
|
|
|
|
await trx.raw(`DELETE FROM ${r.name}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// The supervisor expects this value to already have
|
|
|
|
// been pre-populated
|
|
|
|
await trx('deviceConfig').insert({ targetValues: '{}' });
|
|
|
|
});
|
2019-09-12 15:26:21 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
fs.unlinkSync(process.env.DATABASE_PATH_2!);
|
|
|
|
} catch (e) {
|
|
|
|
/* ignore /*/
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
fs.unlinkSync(process.env.DATABASE_PATH_3!);
|
|
|
|
} catch (e) {
|
|
|
|
/* ignore /*/
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
fs.unlinkSync(process.env.LED_FILE!);
|
|
|
|
} catch (e) {
|
|
|
|
/* ignore /*/
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
fs.writeFileSync(
|
|
|
|
'./test/data/config.json',
|
|
|
|
fs.readFileSync('./test/data/testconfig.json'),
|
|
|
|
);
|
|
|
|
fs.writeFileSync(
|
|
|
|
'./test/data/config-apibinder.json',
|
|
|
|
fs.readFileSync('./test/data/testconfig-apibinder.json'),
|
|
|
|
);
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
'./test/data/config-apibinder-offline.json',
|
|
|
|
fs.readFileSync('./test/data/testconfig-apibinder-offline.json'),
|
|
|
|
);
|
2020-06-02 13:29:05 +00:00
|
|
|
fs.writeFileSync(
|
2019-09-12 15:26:21 +00:00
|
|
|
'./test/data/config-apibinder-offline2.json',
|
|
|
|
fs.readFileSync('./test/data/testconfig-apibinder-offline2.json'),
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
/* ignore /*/
|
|
|
|
}
|
2020-06-02 13:29:05 +00:00
|
|
|
|
|
|
|
// @ts-expect-error using private properties
|
|
|
|
config.configJsonBackend.cache = await config.configJsonBackend.read();
|
|
|
|
await config.generateRequiredFields();
|
2019-09-12 15:26:21 +00:00
|
|
|
};
|