-
Notifications
You must be signed in to change notification settings - Fork 952
feat: allow bypassing current CORS magic based on template config #18706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
94e423b
b2e9c6d
5b2b80e
1af9d2f
6c136cf
8b21d0c
20c3ffd
20dbf97
432aff6
e75fb3b
5b5e766
039240b
8251d8e
22c0711
a5ad58b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
DROP VIEW IF EXISTS template_with_names; | ||
CREATE VIEW template_with_names AS | ||
SELECT templates.id, | ||
templates.created_at, | ||
templates.updated_at, | ||
templates.organization_id, | ||
templates.deleted, | ||
templates.name, | ||
templates.provisioner, | ||
templates.active_version_id, | ||
templates.description, | ||
templates.default_ttl, | ||
templates.created_by, | ||
templates.icon, | ||
templates.user_acl, | ||
templates.group_acl, | ||
templates.display_name, | ||
templates.allow_user_cancel_workspace_jobs, | ||
templates.allow_user_autostart, | ||
templates.allow_user_autostop, | ||
templates.failure_ttl, | ||
templates.time_til_dormant, | ||
templates.time_til_dormant_autodelete, | ||
templates.autostop_requirement_days_of_week, | ||
templates.autostop_requirement_weeks, | ||
templates.autostart_block_days_of_week, | ||
templates.require_active_version, | ||
templates.deprecated, | ||
templates.activity_bump, | ||
templates.max_port_sharing_level, | ||
templates.use_classic_parameter_flow, | ||
COALESCE(visible_users.avatar_url, ''::text) AS created_by_avatar_url, | ||
COALESCE(visible_users.username, ''::text) AS created_by_username, | ||
COALESCE(visible_users.name, ''::text) AS created_by_name, | ||
COALESCE(organizations.name, ''::text) AS organization_name, | ||
COALESCE(organizations.display_name, ''::text) AS organization_display_name, | ||
COALESCE(organizations.icon, ''::text) AS organization_icon | ||
FROM ((templates | ||
LEFT JOIN visible_users ON ((templates.created_by = visible_users.id))) | ||
LEFT JOIN organizations ON ((templates.organization_id = organizations.id))); | ||
|
||
COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.'; | ||
|
||
ALTER TABLE templates DROP COLUMN cors_behavior; | ||
|
||
DROP TYPE IF EXISTS cors_behavior; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
CREATE TYPE cors_behavior AS ENUM ( | ||
'simple', | ||
'passthru' | ||
); | ||
|
||
ALTER TABLE templates | ||
ADD COLUMN cors_behavior cors_behavior NOT NULL DEFAULT 'simple'::cors_behavior; | ||
|
||
-- Update the template_with_users view by recreating it. | ||
DROP VIEW IF EXISTS template_with_names; | ||
CREATE VIEW template_with_names AS | ||
SELECT templates.id, | ||
templates.created_at, | ||
templates.updated_at, | ||
templates.organization_id, | ||
templates.deleted, | ||
templates.name, | ||
templates.provisioner, | ||
templates.active_version_id, | ||
templates.description, | ||
templates.default_ttl, | ||
templates.created_by, | ||
templates.icon, | ||
templates.user_acl, | ||
templates.group_acl, | ||
templates.display_name, | ||
templates.allow_user_cancel_workspace_jobs, | ||
templates.allow_user_autostart, | ||
templates.allow_user_autostop, | ||
templates.failure_ttl, | ||
templates.time_til_dormant, | ||
templates.time_til_dormant_autodelete, | ||
templates.autostop_requirement_days_of_week, | ||
templates.autostop_requirement_weeks, | ||
templates.autostart_block_days_of_week, | ||
templates.require_active_version, | ||
templates.deprecated, | ||
templates.activity_bump, | ||
templates.max_port_sharing_level, | ||
templates.use_classic_parameter_flow, | ||
templates.cors_behavior, -- <--- adding this column | ||
COALESCE(visible_users.avatar_url, ''::text) AS created_by_avatar_url, | ||
COALESCE(visible_users.username, ''::text) AS created_by_username, | ||
COALESCE(visible_users.name, ''::text) AS created_by_name, | ||
COALESCE(organizations.name, ''::text) AS organization_name, | ||
COALESCE(organizations.display_name, ''::text) AS organization_display_name, | ||
COALESCE(organizations.icon, ''::text) AS organization_icon | ||
FROM ((templates | ||
LEFT JOIN visible_users ON ((templates.created_by = visible_users.id))) | ||
LEFT JOIN organizations ON ((templates.organization_id = organizations.id))); | ||
|
||
COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Re-order operations to avoid unnecessary view recompilation locks
You drop
template_with_names
, immediately re-create it, and then further mutatetemplates
below.A cleaner sequence is:
DROP VIEW …
ALTER TABLE templates DROP COLUMN cors_behavior
DROP TYPE …
CREATE VIEW …
This prevents the brand-new view from being invalidated seconds later by the table rewrite that occurs when a column is dropped, reducing lock time and avoiding double parse/plan work.
Re-create the view after the
DROP COLUMN
/DROP TYPE
statements.This is a small change but removes an extra table lock and keeps the migration intent crystal clear.
🤖 Prompt for AI Agents