Skip to content

Commit 081005b

Browse files
authored
Normalize existing website column of organization (#1481)
1 parent b052355 commit 081005b

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- it's a destructive operation in up migration, so we can't really undo it
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
DO
2+
$$
3+
DECLARE
4+
org_record organizations%ROWTYPE;
5+
correct_url text;
6+
BEGIN
7+
FOR org_record IN (SELECT *
8+
FROM organizations
9+
WHERE website LIKE 'http://%'
10+
OR website LIKE 'https://%'
11+
OR website LIKE 'www.%')
12+
LOOP
13+
correct_url := (SELECT CASE
14+
WHEN position('www.' in org_record.website) > 0 THEN
15+
split_part(split_part(org_record.website, 'www.', 2), '/', 1)
16+
ELSE
17+
split_part(split_part(org_record.website, '//', 2), '/', 1)
18+
END);
19+
RAISE NOTICE 'org id: %, fixed url: %', org_record.id, correct_url;
20+
UPDATE organizations SET website = correct_url WHERE id = org_record.id;
21+
END LOOP;
22+
END;
23+
$$;

backend/src/database/repositories/organizationRepository.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,16 +1279,7 @@ class OrganizationRepository {
12791279
// Check if organization exists
12801280
const organization = await options.database.organization.findOne({
12811281
where: {
1282-
website: {
1283-
[Sequelize.Op.or]: [
1284-
// Matches URLs having 'http://' or 'https://'
1285-
{ [Sequelize.Op.iLike]: `%://${domain}` },
1286-
// Matches URLs having 'www'
1287-
{ [Sequelize.Op.iLike]: `%://www.${domain}` },
1288-
// Matches URLs that doesn't have 'http://' or 'https://' and 'www'
1289-
{ [Sequelize.Op.iLike]: `${domain}` },
1290-
],
1291-
},
1282+
website: domain,
12921283
tenantId: currentTenant.id,
12931284
},
12941285
transaction,

services/apps/data_sink_worker/src/repo/organization.repo.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,7 @@ export class OrganizationRepository extends RepositoryBase<OrganizationRepositor
323323
organizations o
324324
WHERE
325325
o."tenantId" = $(tenantId) AND
326-
(
327-
o.website ILIKE $(protocolDomain) OR
328-
o.website ILIKE $(domainWithWww) OR
329-
o.website ILIKE $(domain)
330-
) AND
326+
o.website = $(domain) AND
331327
o.id IN (
332328
SELECT os."organizationId"
333329
FROM "organizationSegments" os
@@ -336,8 +332,6 @@ export class OrganizationRepository extends RepositoryBase<OrganizationRepositor
336332
`,
337333
{
338334
tenantId,
339-
protocolDomain: `%://${domain}`,
340-
domainWithWww: `%://www.${domain}`,
341335
domain,
342336
segmentId,
343337
},

0 commit comments

Comments
 (0)