Feature/siprec server (#49)

* upgrade schema to 0.7.6 if necessary

* db upgrade

* db upgrade
This commit is contained in:
Dave Horton
2022-07-28 16:17:39 +01:00
committed by GitHub
parent f83cc25098
commit 69f36f5a51
4 changed files with 58 additions and 13 deletions

View File

@@ -365,7 +365,7 @@ CREATE TABLE webhooks
(
webhook_sid CHAR(36) NOT NULL UNIQUE ,
url VARCHAR(1024) NOT NULL,
method ENUM("GET","POST","WS") NOT NULL DEFAULT 'POST',
method ENUM("GET","POST") NOT NULL DEFAULT 'POST',
username VARCHAR(255),
password VARCHAR(255),
PRIMARY KEY (webhook_sid)
@@ -422,6 +422,7 @@ subspace_client_id VARCHAR(255),
subspace_client_secret VARCHAR(255),
subspace_sip_teleport_id VARCHAR(255),
subspace_sip_teleport_destinations VARCHAR(255),
siprec_hook_sid CHAR(36),
PRIMARY KEY (account_sid)
) COMMENT='An enterprise that uses the platform for comm services';
@@ -576,4 +577,6 @@ ALTER TABLE accounts ADD FOREIGN KEY queue_event_hook_sid_idxfk (queue_event_hoo
ALTER TABLE accounts ADD FOREIGN KEY device_calling_application_sid_idxfk (device_calling_application_sid) REFERENCES applications (application_sid);
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE accounts ADD FOREIGN KEY siprec_hook_sid_idxfk (siprec_hook_sid) REFERENCES webhooks (webhook_sid);
SET FOREIGN_KEY_CHECKS=1;

View File

@@ -1412,7 +1412,7 @@
</location>
<size>
<width>318.00</width>
<height>420.00</height>
<height>440.00</height>
</size>
<zorder>4</zorder>
<SQLField>
@@ -1577,6 +1577,19 @@
<type><![CDATA[VARCHAR(255)]]></type>
<uid><![CDATA[2A70CC94-123D-4AF1-9881-F876051D8CB5]]></uid>
</SQLField>
<SQLField>
<name><![CDATA[siprec_hook_sid]]></name>
<type><![CDATA[CHAR(36)]]></type>
<referencesField>webhook_sid</referencesField>
<referencesTable>webhooks</referencesTable>
<referencesField><![CDATA[webhook_sid]]></referencesField>
<referencesTable><![CDATA[webhooks]]></referencesTable>
<sourceCardinality>4</sourceCardinality>
<destinationCardinality>2</destinationCardinality>
<referencesFieldUID><![CDATA[E046BA30-BC18-483C-A5C8-766E7160F574]]></referencesFieldUID>
<referencesTableUID><![CDATA[64D64CB9-0990-4C68-BE71-F9FD43C2BE19]]></referencesTableUID>
<uid><![CDATA[4B8283B4-5E16-4846-A79D-12C6B2E73C86]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[25]]></labelWindowIndex>
<objectComment><![CDATA[An enterprise that uses the platform for comm services]]></objectComment>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
@@ -1855,7 +1868,7 @@
<objectComment><![CDATA[if not null, this number is a test number for the associated service provider]]></objectComment>
<uid><![CDATA[D2D46B75-F9C7-42A5-8D8C-4A8412C75ECA]]></uid>
</SQLField>
<labelWindowIndex><![CDATA[25]]></labelWindowIndex>
<labelWindowIndex><![CDATA[26]]></labelWindowIndex>
<objectComment><![CDATA[A phone number that has been assigned to an account]]></objectComment>
<ui.treeExpanded><![CDATA[1]]></ui.treeExpanded>
<uid><![CDATA[BA650DDC-AC7B-4DFE-A5E5-828C75607807]]></uid>
@@ -2433,17 +2446,17 @@
<overviewPanelHidden><![CDATA[0]]></overviewPanelHidden>
<pageBoundariesVisible><![CDATA[0]]></pageBoundariesVisible>
<PageGridVisible><![CDATA[0]]></PageGridVisible>
<RightSidebarWidth><![CDATA[2154.000000]]></RightSidebarWidth>
<RightSidebarWidth><![CDATA[1235.000000]]></RightSidebarWidth>
<sidebarIndex><![CDATA[2]]></sidebarIndex>
<snapToGrid><![CDATA[0]]></snapToGrid>
<SourceSidebarWidth><![CDATA[0.000000]]></SourceSidebarWidth>
<SQLEditorFileFormatVersion><![CDATA[4]]></SQLEditorFileFormatVersion>
<uid><![CDATA[58C99A00-06C9-478C-A667-C63842E088F3]]></uid>
<windowHeight><![CDATA[977.000000]]></windowHeight>
<windowLocationX><![CDATA[1230.000000]]></windowLocationX>
<windowLocationY><![CDATA[80.000000]]></windowLocationY>
<windowScrollOrigin><![CDATA[{0, 0}]]></windowScrollOrigin>
<windowWidth><![CDATA[2431.000000]]></windowWidth>
<windowHeight><![CDATA[833.000000]]></windowHeight>
<windowLocationX><![CDATA[0.000000]]></windowLocationX>
<windowLocationY><![CDATA[111.000000]]></windowLocationY>
<windowScrollOrigin><![CDATA[{172, 109}]]></windowScrollOrigin>
<windowWidth><![CDATA[1512.000000]]></windowWidth>
</SQLDocumentInfo>
<AllowsIndexRenamingOnInsert><![CDATA[1]]></AllowsIndexRenamingOnInsert>
<defaultLabelExpanded><![CDATA[1]]></defaultLabelExpanded>

View File

@@ -4,6 +4,7 @@ const mysql = require('mysql2/promise');
const {readFile} = require('fs/promises');
const {execSync} = require('child_process');
const {version:desiredVersion} = require('../package.json');
const lookupSipGatewayBySignalingAddress = require('@jambonz/db-helpers/lib/lookup-sip-gateway-by-signaling-address');
const logger = require('pino')();
logger.info(`upgrade-jambonz-db: desired version ${desiredVersion}`);
@@ -22,6 +23,12 @@ const opts = {
multipleStatements: true
};
const sql = {
'7006': [
'ALTER TABLE `accounts` ADD COLUMN `siprec_hook_sid` CHAR(36)'
]
};
const doIt = async() => {
let connection;
try {
@@ -36,9 +43,30 @@ const doIt = async() => {
/* does the schema exist at all ? */
const [r] = await connection.execute('SELECT version from schema_version');
if (r.length) {
//TODO: check against desired version and perform upgrades
logger.info(`current version is ${r[0].version}, no upgrade will be performed`);
const {version} = r[0];
const arr = /v?(\d+)\.(\d+)\.(\d+)/.exec(version);
if (arr) {
const upgrades = [];
logger.info(`performing schema migration: ${version} => ${desiredVersion}`);
const val = (1000 * arr[1]) + (100 * arr[2]) + arr[3];
logger.info(`current schema value: ${val}`);
if (val < 7006) upgrades.push(...sql['7006']);
// perform all upgrades
logger.info({upgrades}, 'performing upgrades..');
try {
for (const upgrade of upgrades) {
logger.info(`upgrading schema with : "${upgrade}"`);
await connection.execute(upgrade);
}
} catch (err) {
logger.error({err}, 'Error performing upgrade');
process.exit(1);
}
}
await connection.end();
logger.info(`schema migration to ${desiredVersion} completed`);
return;
}
} catch (err) {
@@ -70,5 +98,6 @@ const seedDatabase = async(connection) => {
await connection.query(sql);
};
doIt();

View File

@@ -1,6 +1,6 @@
{
"name": "jambonz-api-server",
"version": "v0.7.5",
"version": "v0.7.6",
"description": "",
"main": "app.js",
"scripts": {