fixes to sqlite migration

This commit is contained in:
miloschwartz 2025-07-16 11:47:05 -07:00
parent 021bc073a2
commit d1489a9a78
No known key found for this signature in database
2 changed files with 30 additions and 27 deletions

View file

@ -2,7 +2,7 @@ import path from "path";
import { fileURLToPath } from "url";
// This is a placeholder value replaced by the build process
export const APP_VERSION = "1.6.0";
export const APP_VERSION = "1.7.0";
export const __FILENAME = fileURLToPath(import.meta.url);
export const __DIRNAME = path.dirname(__FILENAME);

View file

@ -16,7 +16,7 @@ export default async function migration() {
CREATE TABLE 'clientSites' (
'clientId' integer NOT NULL,
'siteId' integer NOT NULL,
'isRelayed' integer DEFAULT false NOT NULL,
'isRelayed' integer DEFAULT 0 NOT NULL,
FOREIGN KEY ('clientId') REFERENCES 'clients'('id') ON UPDATE no action ON DELETE cascade,
FOREIGN KEY ('siteId') REFERENCES 'sites'('siteId') ON UPDATE no action ON DELETE cascade
);
@ -33,7 +33,7 @@ export default async function migration() {
'lastBandwidthUpdate' text,
'lastPing' text,
'type' text NOT NULL,
'online' integer DEFAULT false NOT NULL,
'online' integer DEFAULT 0 NOT NULL,
'endpoint' text,
'lastHolePunch' integer,
FOREIGN KEY ('orgId') REFERENCES 'orgs'('orgId') ON UPDATE no action ON DELETE cascade,
@ -98,10 +98,9 @@ export default async function migration() {
);
`);
})(); // <-- executes the transaction immediately
db.pragma("foreign_keys = OFF");
db.transaction(() => {
db.pragma("foreign_keys = OFF");
db.exec(`
CREATE TABLE '__new_sites' (
'siteId' integer PRIMARY KEY AUTOINCREMENT NOT NULL,
@ -115,41 +114,45 @@ export default async function migration() {
'bytesOut' integer DEFAULT 0,
'lastBandwidthUpdate' text,
'type' text NOT NULL,
'online' integer DEFAULT false NOT NULL,
'online' integer DEFAULT 0 NOT NULL,
'address' text,
'endpoint' text,
'publicKey' text,
'lastHolePunch' integer,
'listenPort' integer,
'dockerSocketEnabled' integer DEFAULT true NOT NULL,
'dockerSocketEnabled' integer DEFAULT 1 NOT NULL,
FOREIGN KEY ('orgId') REFERENCES 'orgs'('orgId') ON UPDATE no action ON DELETE cascade,
FOREIGN KEY ('exitNode') REFERENCES 'exitNodes'('exitNodeId') ON UPDATE no action ON DELETE set null
);
INSERT INTO '__new_sites'("siteId", "orgId", "niceId", "exitNode", "name", "pubKey", "subnet", "bytesIn", "bytesOut", "lastBandwidthUpdate", "type", "online", "address", "endpoint", "publicKey", "lastHolePunch", "listenPort", "dockerSocketEnabled") SELECT "siteId", "orgId", "niceId", "exitNode", "name", "pubKey", "subnet", "bytesIn", "bytesOut", "lastBandwidthUpdate", "type", "online", "address", "endpoint", "publicKey", "lastHolePunch", "listenPort", "dockerSocketEnabled" FROM 'sites';
INSERT INTO '__new_sites' (
'siteId', 'orgId', 'niceId', 'exitNode', 'name', 'pubKey', 'subnet', 'bytesIn', 'bytesOut', 'lastBandwidthUpdate', 'type', 'online', 'address', 'endpoint', 'publicKey', 'lastHolePunch', 'listenPort', 'dockerSocketEnabled'
)
SELECT siteId, orgId, niceId, exitNode, name, pubKey, subnet, bytesIn, bytesOut, lastBandwidthUpdate, type, online, NULL, NULL, NULL, NULL, NULL, dockerSocketEnabled
FROM sites;
DROP TABLE 'sites';
ALTER TABLE '__new_sites' RENAME TO 'sites';
`);
})(); // <-- executes the transaction immediately
db.pragma("foreign_keys = ON");
db.transaction(() => {
db.pragma("foreign_keys = ON");
db.exec(`
ALTER TABLE 'domains' ADD 'type' text;
ALTER TABLE 'domains' ADD 'verified' integer DEFAULT false NOT NULL;
ALTER TABLE 'domains' ADD 'failed' integer DEFAULT false NOT NULL;
ALTER TABLE 'domains' ADD 'verified' integer DEFAULT 0 NOT NULL;
ALTER TABLE 'domains' ADD 'failed' integer DEFAULT 0 NOT NULL;
ALTER TABLE 'domains' ADD 'tries' integer DEFAULT 0 NOT NULL;
ALTER TABLE 'exitNodes' ADD 'maxConnections' integer;
ALTER TABLE 'newt' ADD 'version' text;
ALTER TABLE 'orgs' ADD 'subnet' text NOT NULL;
ALTER TABLE 'user' ADD 'twoFactorSetupRequested' integer DEFAULT false;
ALTER TABLE 'user' ADD 'twoFactorSetupRequested' integer DEFAULT 0;
ALTER TABLE 'resources' DROP COLUMN 'isBaseDomain';
`);
})(); // <-- executes the transaction immediately
console.log(`Migrated database schema`);
} catch (e) {
console.log("Unable to migrate database schema");
console.log(e);
throw e;
}
console.log(`${version} migration complete`);