diff --git a/migrations/20240222153325-appPortBindings-add-count.js b/migrations/20240222153325-appPortBindings-add-count.js new file mode 100644 index 000000000..817dd447d --- /dev/null +++ b/migrations/20240222153325-appPortBindings-add-count.js @@ -0,0 +1,9 @@ +'use strict'; + +exports.up = async function (db) { + await db.runSql('ALTER TABLE appPortBindings ADD COLUMN count INTEGER DEFAULT 1'); +}; + +exports.down = async function (db) { + await db.runSql('ALTER TABLE appPortBindings DROP COLUMN count'); +}; diff --git a/migrations/schema.sql b/migrations/schema.sql index 465717b16..c7a4fcf61 100644 --- a/migrations/schema.sql +++ b/migrations/schema.sql @@ -115,6 +115,7 @@ CREATE TABLE IF NOT EXISTS appPortBindings( type VARCHAR(8) NOT NULL DEFAULT "tcp", environmentVariable VARCHAR(128) NOT NULL, appId VARCHAR(128) NOT NULL, + count INTEGER DEFAULT 1, FOREIGN KEY(appId) REFERENCES apps(id), PRIMARY KEY(hostPort)); diff --git a/src/apps.js b/src/apps.js index 9fb725acf..046341d0b 100644 --- a/src/apps.js +++ b/src/apps.js @@ -847,8 +847,8 @@ async function add(id, appStoreId, manifest, subdomain, domain, portBindings, da Object.keys(portBindings).forEach(function (env) { queries.push({ - query: 'INSERT INTO appPortBindings (environmentVariable, hostPort, type, appId) VALUES (?, ?, ?, ?)', - args: [ env, portBindings[env].hostPort, portBindings[env].type, id ] + query: 'INSERT INTO appPortBindings (environmentVariable, hostPort, type, appId, count) VALUES (?, ?, ?, ?, ?)', + args: [ env, portBindings[env].hostPort, portBindings[env].type, id, portBindings[env].portCount || 1 ] }); }); @@ -919,8 +919,8 @@ async function updateWithConstraints(id, app, constraints) { // replace entries by app id queries.push({ query: 'DELETE FROM appPortBindings WHERE appId = ?', args: [ id ] }); Object.keys(portBindings).forEach(function (env) { - const values = [ portBindings[env].hostPort, portBindings[env].type, env, id ]; - queries.push({ query: 'INSERT INTO appPortBindings (hostPort, type, environmentVariable, appId) VALUES(?, ?, ?, ?)', args: values }); + const values = [ portBindings[env].hostPort, portBindings[env].type, env, id, portBindings[env].portCount || 1 ]; + queries.push({ query: 'INSERT INTO appPortBindings (hostPort, type, environmentVariable, appId, count) VALUES(?, ?, ?, ?, ?)', args: values }); }); }