Skip to content

chore: move default everyone group to a migration #12435

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

Merged
merged 1 commit into from
Mar 12, 2024

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Mar 5, 2024

No description provided.

Comment on lines +91 to +96

_, err = q.InsertAllUsersGroup(context.Background(), defaultOrg.ID)
if err != nil {
panic(fmt.Errorf("failed to create default group: %w", err))
}

Copy link
Member Author

Choose a reason for hiding this comment

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

dbmem doesn't have the concept of "migrations". I wonder if we should have something similar rather than chucking them here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think "migrations" is the right concept, since we don't ever change an old dbmem into a new one, but it might make sense to have an abstraction that populates the initial contents of the database, which is what this does...

@Emyrk Emyrk requested a review from spikecurtis March 5, 2024 20:39
Comment on lines +91 to +96

_, err = q.InsertAllUsersGroup(context.Background(), defaultOrg.ID)
if err != nil {
panic(fmt.Errorf("failed to create default group: %w", err))
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think "migrations" is the right concept, since we don't ever change an old dbmem into a new one, but it might make sense to have an abstraction that populates the initial contents of the database, which is what this does...

'Everyone',
-- Org ID and group ID must match.
(SELECT id FROM organizations WHERE is_default = true LIMIT 1),
(SELECT id FROM organizations WHERE is_default = true LIMIT 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is LIMIT 1 required for SQL to correctly cast a rowset into a scaler? The unique index on is_default should ensure there is exactly one organization where it is true.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not required, the unique index should protect this.

I added the LIMIT 1 for defensive programming in our migrations since they can prevent boot of Coderd.

@Emyrk Emyrk marked this pull request as ready for review March 6, 2024 13:31
@Emyrk Emyrk requested a review from spikecurtis March 8, 2024 14:43
@Emyrk Emyrk merged commit e11d3ca into main Mar 12, 2024
@Emyrk Emyrk deleted the stevenmasley/always_everyone_group branch March 12, 2024 14:27
@github-actions github-actions bot locked and limited conversation to collaborators Mar 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants