Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- it's a destructive operation in up migration, so we can't really undo it
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
DO
$$
DECLARE
org_record organizations%ROWTYPE;
correct_url text;
BEGIN
FOR org_record IN (SELECT *
FROM organizations
WHERE website LIKE 'http://%'
OR website LIKE 'https://%'
OR website LIKE 'www.%')
LOOP
correct_url := (SELECT CASE
WHEN position('www.' in org_record.website) > 0 THEN
split_part(split_part(org_record.website, 'www.', 2), '/', 1)
ELSE
split_part(split_part(org_record.website, '//', 2), '/', 1)
END);
RAISE NOTICE 'org id: %, fixed url: %', org_record.id, correct_url;
UPDATE organizations SET website = correct_url WHERE id = org_record.id;
END LOOP;
END;
$$;
11 changes: 1 addition & 10 deletions backend/src/database/repositories/organizationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1279,16 +1279,7 @@ class OrganizationRepository {
// Check if organization exists
const organization = await options.database.organization.findOne({
where: {
website: {
[Sequelize.Op.or]: [
// Matches URLs having 'http://' or 'https://'
{ [Sequelize.Op.iLike]: `%://${domain}` },
// Matches URLs having 'www'
{ [Sequelize.Op.iLike]: `%://www.${domain}` },
// Matches URLs that doesn't have 'http://' or 'https://' and 'www'
{ [Sequelize.Op.iLike]: `${domain}` },
],
},
website: domain,
tenantId: currentTenant.id,
},
transaction,
Expand Down
8 changes: 1 addition & 7 deletions services/apps/data_sink_worker/src/repo/organization.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,7 @@ export class OrganizationRepository extends RepositoryBase<OrganizationRepositor
organizations o
WHERE
o."tenantId" = $(tenantId) AND
(
o.website ILIKE $(protocolDomain) OR
o.website ILIKE $(domainWithWww) OR
o.website ILIKE $(domain)
) AND
o.website = $(domain) AND
o.id IN (
SELECT os."organizationId"
FROM "organizationSegments" os
Expand All @@ -336,8 +332,6 @@ export class OrganizationRepository extends RepositoryBase<OrganizationRepositor
`,
{
tenantId,
protocolDomain: `%://${domain}`,
domainWithWww: `%://www.${domain}`,
domain,
segmentId,
},
Expand Down