-
Notifications
You must be signed in to change notification settings - Fork 943
chore: ensure default org always exists #12412
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
Changes from 1 commit
e4b1bb8
b4a4dd4
627c9f8
179828c
db8da5a
b830625
6b086c6
9997f59
3977c71
d35933d
1b8690f
c9af8c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
First user just joins the org created by the migration
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- There is no down. If the org is created, just let it be. Deleting an org feels dangerous in a migration. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- This ensures a default organization always exists. | ||
INSERT INTO | ||
organizations(id, name, description, created_at, updated_at, is_default) | ||
SELECT | ||
-- Avoid calling it "default" as we are reserving that word as a keyword to fetch | ||
-- the default org regardless of the name. | ||
gen_random_uuid(), | ||
'first-organization', | ||
'Builtin default organization.', | ||
now(), | ||
now(), | ||
true | ||
WHERE | ||
-- Only insert if no organizations exist. | ||
NOT EXISTS (SELECT * FROM organizations) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,16 +171,25 @@ func (api *API) postFirstUser(rw http.ResponseWriter, r *http.Request) { | |
} | ||
} | ||
|
||
defaultOrg, err := api.Database.GetDefaultOrganization(ctx) | ||
if err != nil { | ||
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ | ||
Message: "Internal error fetching default organization. If you are encountering this error, you will have to restart the Coder deployment.", | ||
Detail: err.Error(), | ||
}) | ||
return | ||
} | ||
|
||
//nolint:gocritic // needed to create first user | ||
user, organizationID, err := api.CreateUser(dbauthz.AsSystemRestricted(ctx), api.Database, CreateUserRequest{ | ||
CreateUserRequest: codersdk.CreateUserRequest{ | ||
Email: createUser.Email, | ||
Username: createUser.Username, | ||
Password: createUser.Password, | ||
// Create an org for the first user. | ||
OrganizationID: uuid.Nil, | ||
OrganizationID: defaultOrg.ID, | ||
}, | ||
CreateOrganization: true, | ||
CreateOrganization: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can remove this field, which also allows cleaning up a lot of cruft in userauth.go There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh you are right. I think we can drop the |
||
LoginType: database.LoginTypePassword, | ||
}) | ||
if err != nil { | ||
|
Uh oh!
There was an error while loading. Please reload this page.