mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-02 08:09:10 +00:00
Merge dev into fix/log-analytics-adjustments
This commit is contained in:
@@ -9,7 +9,9 @@ export default async function migration() {
|
||||
try {
|
||||
await db.execute(sql`BEGIN`);
|
||||
|
||||
await db.execute(sql`UPDATE "resourceRules" SET "match" = 'COUNTRY' WHERE "match" = 'GEOIP'`);
|
||||
await db.execute(
|
||||
sql`UPDATE "resourceRules" SET "match" = 'COUNTRY' WHERE "match" = 'GEOIP'`
|
||||
);
|
||||
|
||||
await db.execute(sql`
|
||||
CREATE TABLE "accessAuditLog" (
|
||||
@@ -92,40 +94,97 @@ export default async function migration() {
|
||||
);
|
||||
`);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "blueprints" ADD CONSTRAINT "blueprints_orgId_orgs_orgId_fk" FOREIGN KEY ("orgId") REFERENCES "public"."orgs"("orgId") ON DELETE cascade ON UPDATE no action;`);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "blueprints" ADD CONSTRAINT "blueprints_orgId_orgs_orgId_fk" FOREIGN KEY ("orgId") REFERENCES "public"."orgs"("orgId") ON DELETE cascade ON UPDATE no action;`
|
||||
);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "remoteExitNode" ADD COLUMN "secondaryVersion" varchar;`);
|
||||
await db.execute(sql`ALTER TABLE "resources" DROP CONSTRAINT "resources_skipToIdpId_idp_idpId_fk";`);
|
||||
await db.execute(sql`ALTER TABLE "domains" ADD COLUMN "certResolver" varchar;`);
|
||||
await db.execute(sql`ALTER TABLE "domains" ADD COLUMN "customCertResolver" varchar;`);
|
||||
await db.execute(sql`ALTER TABLE "domains" ADD COLUMN "preferWildcardCert" boolean;`);
|
||||
await db.execute(sql`ALTER TABLE "orgs" ADD COLUMN "requireTwoFactor" boolean;`);
|
||||
await db.execute(sql`ALTER TABLE "orgs" ADD COLUMN "maxSessionLengthHours" integer;`);
|
||||
await db.execute(sql`ALTER TABLE "orgs" ADD COLUMN "passwordExpiryDays" integer;`);
|
||||
await db.execute(sql`ALTER TABLE "orgs" ADD COLUMN "settingsLogRetentionDaysRequest" integer DEFAULT 7 NOT NULL;`);
|
||||
await db.execute(sql`ALTER TABLE "orgs" ADD COLUMN "settingsLogRetentionDaysAccess" integer DEFAULT 0 NOT NULL;`);
|
||||
await db.execute(sql`ALTER TABLE "orgs" ADD COLUMN "settingsLogRetentionDaysAction" integer DEFAULT 0 NOT NULL;`);
|
||||
await db.execute(sql`ALTER TABLE "resourceSessions" ADD COLUMN "issuedAt" bigint;`);
|
||||
await db.execute(sql`ALTER TABLE "resources" ADD COLUMN "proxyProtocol" boolean DEFAULT false NOT NULL;`);
|
||||
await db.execute(sql`ALTER TABLE "resources" ADD COLUMN "proxyProtocolVersion" integer DEFAULT 1;`);
|
||||
await db.execute(sql`ALTER TABLE "session" ADD COLUMN "issuedAt" bigint;`);
|
||||
await db.execute(sql`ALTER TABLE "user" ADD COLUMN "lastPasswordChange" bigint;`);
|
||||
await db.execute(sql`ALTER TABLE "accessAuditLog" ADD CONSTRAINT "accessAuditLog_orgId_orgs_orgId_fk" FOREIGN KEY ("orgId") REFERENCES "public"."orgs"("orgId") ON DELETE cascade ON UPDATE no action;`);
|
||||
await db.execute(sql`ALTER TABLE "actionAuditLog" ADD CONSTRAINT "actionAuditLog_orgId_orgs_orgId_fk" FOREIGN KEY ("orgId") REFERENCES "public"."orgs"("orgId") ON DELETE cascade ON UPDATE no action;`);
|
||||
await db.execute(sql`ALTER TABLE "dnsRecords" ADD CONSTRAINT "dnsRecords_domainId_domains_domainId_fk" FOREIGN KEY ("domainId") REFERENCES "public"."domains"("domainId") ON DELETE cascade ON UPDATE no action;`);
|
||||
await db.execute(sql`ALTER TABLE "requestAuditLog" ADD CONSTRAINT "requestAuditLog_orgId_orgs_orgId_fk" FOREIGN KEY ("orgId") REFERENCES "public"."orgs"("orgId") ON DELETE cascade ON UPDATE no action;`);
|
||||
await db.execute(sql`CREATE INDEX "idx_identityAuditLog_timestamp" ON "accessAuditLog" USING btree ("timestamp");`);
|
||||
await db.execute(sql`CREATE INDEX "idx_identityAuditLog_org_timestamp" ON "accessAuditLog" USING btree ("orgId","timestamp");`);
|
||||
await db.execute(sql`CREATE INDEX "idx_actionAuditLog_timestamp" ON "actionAuditLog" USING btree ("timestamp");`);
|
||||
await db.execute(sql`CREATE INDEX "idx_actionAuditLog_org_timestamp" ON "actionAuditLog" USING btree ("orgId","timestamp");`);
|
||||
await db.execute(sql`CREATE INDEX "idx_requestAuditLog_timestamp" ON "requestAuditLog" USING btree ("timestamp");`);
|
||||
await db.execute(sql`CREATE INDEX "idx_requestAuditLog_org_timestamp" ON "requestAuditLog" USING btree ("orgId","timestamp");`);
|
||||
await db.execute(sql`ALTER TABLE "resources" ADD CONSTRAINT "resources_skipToIdpId_idp_idpId_fk" FOREIGN KEY ("skipToIdpId") REFERENCES "public"."idp"("idpId") ON DELETE set null ON UPDATE no action;`);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "remoteExitNode" ADD COLUMN "secondaryVersion" varchar;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "resources" DROP CONSTRAINT "resources_skipToIdpId_idp_idpId_fk";`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "domains" ADD COLUMN "certResolver" varchar;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "domains" ADD COLUMN "customCertResolver" varchar;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "domains" ADD COLUMN "preferWildcardCert" boolean;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "orgs" ADD COLUMN "requireTwoFactor" boolean;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "orgs" ADD COLUMN "maxSessionLengthHours" integer;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "orgs" ADD COLUMN "passwordExpiryDays" integer;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "orgs" ADD COLUMN "settingsLogRetentionDaysRequest" integer DEFAULT 7 NOT NULL;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "orgs" ADD COLUMN "settingsLogRetentionDaysAccess" integer DEFAULT 0 NOT NULL;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "orgs" ADD COLUMN "settingsLogRetentionDaysAction" integer DEFAULT 0 NOT NULL;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "resourceSessions" ADD COLUMN "issuedAt" bigint;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "resources" ADD COLUMN "proxyProtocol" boolean DEFAULT false NOT NULL;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "resources" ADD COLUMN "proxyProtocolVersion" integer DEFAULT 1;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "session" ADD COLUMN "issuedAt" bigint;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "user" ADD COLUMN "lastPasswordChange" bigint;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "accessAuditLog" ADD CONSTRAINT "accessAuditLog_orgId_orgs_orgId_fk" FOREIGN KEY ("orgId") REFERENCES "public"."orgs"("orgId") ON DELETE cascade ON UPDATE no action;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "actionAuditLog" ADD CONSTRAINT "actionAuditLog_orgId_orgs_orgId_fk" FOREIGN KEY ("orgId") REFERENCES "public"."orgs"("orgId") ON DELETE cascade ON UPDATE no action;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "dnsRecords" ADD CONSTRAINT "dnsRecords_domainId_domains_domainId_fk" FOREIGN KEY ("domainId") REFERENCES "public"."domains"("domainId") ON DELETE cascade ON UPDATE no action;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "requestAuditLog" ADD CONSTRAINT "requestAuditLog_orgId_orgs_orgId_fk" FOREIGN KEY ("orgId") REFERENCES "public"."orgs"("orgId") ON DELETE cascade ON UPDATE no action;`
|
||||
);
|
||||
await db.execute(
|
||||
sql`CREATE INDEX "idx_identityAuditLog_timestamp" ON "accessAuditLog" USING btree ("timestamp");`
|
||||
);
|
||||
await db.execute(
|
||||
sql`CREATE INDEX "idx_identityAuditLog_org_timestamp" ON "accessAuditLog" USING btree ("orgId","timestamp");`
|
||||
);
|
||||
await db.execute(
|
||||
sql`CREATE INDEX "idx_actionAuditLog_timestamp" ON "actionAuditLog" USING btree ("timestamp");`
|
||||
);
|
||||
await db.execute(
|
||||
sql`CREATE INDEX "idx_actionAuditLog_org_timestamp" ON "actionAuditLog" USING btree ("orgId","timestamp");`
|
||||
);
|
||||
await db.execute(
|
||||
sql`CREATE INDEX "idx_requestAuditLog_timestamp" ON "requestAuditLog" USING btree ("timestamp");`
|
||||
);
|
||||
await db.execute(
|
||||
sql`CREATE INDEX "idx_requestAuditLog_org_timestamp" ON "requestAuditLog" USING btree ("orgId","timestamp");`
|
||||
);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "resources" ADD CONSTRAINT "resources_skipToIdpId_idp_idpId_fk" FOREIGN KEY ("skipToIdpId") REFERENCES "public"."idp"("idpId") ON DELETE set null ON UPDATE no action;`
|
||||
);
|
||||
await db.execute(sql`ALTER TABLE "orgs" DROP COLUMN "settings";`);
|
||||
|
||||
|
||||
// get all of the domains
|
||||
const domainsQuery = await db.execute(sql`SELECT "domainId", "baseDomain" FROM "domains"`);
|
||||
const domainsQuery = await db.execute(
|
||||
sql`SELECT "domainId", "baseDomain" FROM "domains"`
|
||||
);
|
||||
const domains = domainsQuery.rows as {
|
||||
domainId: string;
|
||||
baseDomain: string;
|
||||
@@ -135,11 +194,11 @@ export default async function migration() {
|
||||
// insert two records into the dnsRecords table for each domain
|
||||
await db.execute(sql`
|
||||
INSERT INTO "dnsRecords" ("domainId", "recordType", "baseDomain", "value", "verified")
|
||||
VALUES (${domain.domainId}, 'A', ${`*.${domain.baseDomain}`}, ${'Server IP Address'}, true)
|
||||
VALUES (${domain.domainId}, 'A', ${`*.${domain.baseDomain}`}, ${"Server IP Address"}, true)
|
||||
`);
|
||||
await db.execute(sql`
|
||||
INSERT INTO "dnsRecords" ("domainId", "recordType", "baseDomain", "value", "verified")
|
||||
VALUES (${domain.domainId}, 'A', ${domain.baseDomain}, ${'Server IP Address'}, true)
|
||||
VALUES (${domain.domainId}, 'A', ${domain.baseDomain}, ${"Server IP Address"}, true)
|
||||
`);
|
||||
}
|
||||
|
||||
|
||||
@@ -255,7 +255,9 @@ export default async function migration() {
|
||||
const siteDataQuery = await db.execute(sql`
|
||||
SELECT "orgId" FROM "sites" WHERE "siteId" = ${site.siteId}
|
||||
`);
|
||||
const siteData = siteDataQuery.rows[0] as { orgId: string } | undefined;
|
||||
const siteData = siteDataQuery.rows[0] as
|
||||
| { orgId: string }
|
||||
| undefined;
|
||||
if (!siteData) continue;
|
||||
|
||||
const subnets = site.remoteSubnets.split(",");
|
||||
|
||||
@@ -121,7 +121,7 @@ export default async function migration() {
|
||||
|
||||
try {
|
||||
await db.execute(sql`BEGIN`);
|
||||
|
||||
|
||||
// Update all existing orgs to have the default subnet
|
||||
await db.execute(sql`UPDATE "orgs" SET "subnet" = '100.90.128.0/24'`);
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ export default async function migration() {
|
||||
|
||||
try {
|
||||
// Get the first siteId to use as default
|
||||
const firstSite = await db.execute(sql`SELECT "siteId" FROM "sites" LIMIT 1`);
|
||||
const firstSite = await db.execute(
|
||||
sql`SELECT "siteId" FROM "sites" LIMIT 1`
|
||||
);
|
||||
if (firstSite.rows.length > 0) {
|
||||
firstSiteId = firstSite.rows[0].siteId as number;
|
||||
}
|
||||
@@ -52,33 +54,59 @@ export default async function migration() {
|
||||
"enabled" boolean DEFAULT true NOT NULL
|
||||
);`);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "resources" DROP CONSTRAINT "resources_siteId_sites_siteId_fk";`);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "resources" DROP CONSTRAINT "resources_siteId_sites_siteId_fk";`
|
||||
);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "clients" ALTER COLUMN "lastPing" TYPE integer USING NULL;`);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "clients" ALTER COLUMN "lastPing" TYPE integer USING NULL;`
|
||||
);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "clientSites" ADD COLUMN "endpoint" varchar;`);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "clientSites" ADD COLUMN "endpoint" varchar;`
|
||||
);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "exitNodes" ADD COLUMN "online" boolean DEFAULT false NOT NULL;`);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "exitNodes" ADD COLUMN "online" boolean DEFAULT false NOT NULL;`
|
||||
);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "exitNodes" ADD COLUMN "lastPing" integer;`);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "exitNodes" ADD COLUMN "lastPing" integer;`
|
||||
);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "exitNodes" ADD COLUMN "type" text DEFAULT 'gerbil';`);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "exitNodes" ADD COLUMN "type" text DEFAULT 'gerbil';`
|
||||
);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "olms" ADD COLUMN "version" text;`);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "orgs" ADD COLUMN "createdAt" text;`);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "resources" ADD COLUMN "skipToIdpId" integer;`);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "resources" ADD COLUMN "skipToIdpId" integer;`
|
||||
);
|
||||
|
||||
await db.execute(sql.raw(`ALTER TABLE "targets" ADD COLUMN "siteId" integer NOT NULL DEFAULT ${firstSiteId || 1};`));
|
||||
await db.execute(
|
||||
sql.raw(
|
||||
`ALTER TABLE "targets" ADD COLUMN "siteId" integer NOT NULL DEFAULT ${firstSiteId || 1};`
|
||||
)
|
||||
);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "siteResources" ADD CONSTRAINT "siteResources_siteId_sites_siteId_fk" FOREIGN KEY ("siteId") REFERENCES "public"."sites"("siteId") ON DELETE cascade ON UPDATE no action;`);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "siteResources" ADD CONSTRAINT "siteResources_siteId_sites_siteId_fk" FOREIGN KEY ("siteId") REFERENCES "public"."sites"("siteId") ON DELETE cascade ON UPDATE no action;`
|
||||
);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "siteResources" ADD CONSTRAINT "siteResources_orgId_orgs_orgId_fk" FOREIGN KEY ("orgId") REFERENCES "public"."orgs"("orgId") ON DELETE cascade ON UPDATE no action;`);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "siteResources" ADD CONSTRAINT "siteResources_orgId_orgs_orgId_fk" FOREIGN KEY ("orgId") REFERENCES "public"."orgs"("orgId") ON DELETE cascade ON UPDATE no action;`
|
||||
);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "resources" ADD CONSTRAINT "resources_skipToIdpId_idp_idpId_fk" FOREIGN KEY ("skipToIdpId") REFERENCES "public"."idp"("idpId") ON DELETE cascade ON UPDATE no action;`);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "resources" ADD CONSTRAINT "resources_skipToIdpId_idp_idpId_fk" FOREIGN KEY ("skipToIdpId") REFERENCES "public"."idp"("idpId") ON DELETE cascade ON UPDATE no action;`
|
||||
);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "targets" ADD CONSTRAINT "targets_siteId_sites_siteId_fk" FOREIGN KEY ("siteId") REFERENCES "public"."sites"("siteId") ON DELETE cascade ON UPDATE no action;`);
|
||||
await db.execute(
|
||||
sql`ALTER TABLE "targets" ADD CONSTRAINT "targets_siteId_sites_siteId_fk" FOREIGN KEY ("siteId") REFERENCES "public"."sites"("siteId") ON DELETE cascade ON UPDATE no action;`
|
||||
);
|
||||
|
||||
await db.execute(sql`ALTER TABLE "clients" DROP COLUMN "endpoint";`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user