Skip to content

Conversation

@felixgateru
Copy link
Contributor

@felixgateru felixgateru commented Mar 25, 2025

What type of PR is this?

This is a feature as it adds a route field to channels.

What does this do?

  • Introduces route attribute for channels
  • Updates relevent repository, service and api methods for this addition
  • Updates documentation and tests

Which issue(s) does this PR fix/relate to?

Have you included tests for your changes?

Yes, tests have been added for my changes.

Did you document any new/modified feature?

Yes, api documentation has been updated for the change

Notes

@felixgateru felixgateru requested a review from a team as a code owner March 25, 2025 14:29
@codecov
Copy link

codecov bot commented Mar 25, 2025

Codecov Report

Attention: Patch coverage is 42.85714% with 60 lines in your changes missing coverage. Please review.

Project coverage is 31.19%. Comparing base (7f4633a) to head (e7d7a91).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
channels/mocks/repository.go 0.00% 34 Missing ⚠️
channels/postgres/channels.go 66.66% 11 Missing and 2 partials ⚠️
channels/events/events.go 0.00% 7 Missing ⚠️
channels/api/http/requests.go 57.14% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2772      +/-   ##
==========================================
+ Coverage   27.68%   31.19%   +3.50%     
==========================================
  Files         353       65     -288     
  Lines       55931    15355   -40576     
==========================================
- Hits        15485     4790   -10695     
+ Misses      39679    10312   -29367     
+ Partials      767      253     -514     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@felixgateru felixgateru changed the title SMQ-2761 - Add topic field to channels SMQ-2761 - Add route field to channels Mar 28, 2025
Copy link
Collaborator

@dborovcanin dborovcanin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixgateru Please rebase.

@felixgateru felixgateru force-pushed the smq2761-topics branch 6 times, most recently from 1900dbf to 0aedef8 Compare April 8, 2025 12:01
@felixgateru felixgateru force-pushed the smq2761-topics branch 2 times, most recently from 299a2d3 to 4967efe Compare April 15, 2025 14:54
Comment on lines 67 to 74
Up: []string{
`ALTER TABLE channels ADD COLUMN route VARCHAR(36) NOT NULL;`,
`ALTER TABLE channels ADD CONSTRAINT unique_domain_route UNIQUE (domain_id, route);`,
},
Down: []string{
`ALTER TABLE channels DROP CONSTRAINT unique_domain_route;`,
`ALTER TABLE channels DROP COLUMN route;`,
},
Copy link
Contributor

@arvindh123 arvindh123 May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have applied these migration in existing channels
I get error like this in channels

2025-05-21 14:25:56 {"time":"2025-05-21T08:55:56.963692336Z","level":"ERROR","msg":"failed to apply migrations : ERROR: column \"route\" of relation \"channels\" contains null values (SQLSTATE 23502) handling channels_03"}

In order make this work with existing deployments
We can simply copy channel id to route

-- Step 1: Add the 'route' column, allowing NULLs temporarily
ALTER TABLE channels ADD COLUMN route VARCHAR(36);

-- Step 2: Populate the 'route' column for existing rows with values from 'id'
-- Assuming 'id' is a UUID or a type that can be cast to VARCHAR(36)
-- If 'id' is a different type (e.g., INT), you might need a different casting or conversion
UPDATE channels SET route = id::VARCHAR(36);

-- Step 3: Add the NOT NULL constraint to the 'route' column
-- This will succeed now because all existing rows have a value for 'route'
ALTER TABLE channels ALTER COLUMN route SET NOT NULL;

-- Step 4: Add the unique constraint
ALTER TABLE channels ADD CONSTRAINT unique_domain_route UNIQUE (domain_id, route);

arvindh123
arvindh123 previously approved these changes May 21, 2025
Comment on lines 68 to 71
`ALTER TABLE channels ADD COLUMN route VARCHAR(36);`,
`UPDATE channels SET route = id WHERE route IS NULL;`,
`ALTER TABLE channels ALTER COLUMN route SET NOT NULL;`,
`ALTER TABLE channels ADD CONSTRAINT unique_domain_route UNIQUE (domain_id, route);`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we make route required?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If nothing, routes must not be in UUID format so we can easily and quickly make a difference between ID and route; something like username and email.

}
if req.Channel.Route != "" {
return api.ValidateRoute(req.Channel.Route)
}
Copy link
Contributor

@arvindh123 arvindh123 May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
if req.Channel.Route != "" {
if err := api.ValidateRoute(req.Channel.Route); err != nil {
return err
}
}

Copy link
Contributor

@arvindh123 arvindh123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

domainID: validID,
req: channels.Channel{
Name: valid,
Route: "__invalid",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, add a check for UUID format. We must not allow UUIDs in routes to prevent confusion and make our lives easier.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test here as well:

		{
			desc:     "create channel with UUID route",
			token:    validToken,
			domainID: validID,
			req: channels.Channel{
				Name:  valid,
				Route: testsutil.GenerateUUID(t),
			},
			contentType: contentType,
			status:      http.StatusBadRequest,
			err:         apiutil.ErrInvalidRouteFormat,
		},

Validation testing is fine, but it only works if decoding request works properly, so we to test it here as well.

@dborovcanin dborovcanin merged commit 04f6117 into absmach:main May 21, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add topic field to channels

3 participants