Skip to content

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Feb 28, 2024

Closes #11931

@Emyrk Emyrk requested a review from spikecurtis February 29, 2024 14:31
Base automatically changed from stevenmasley/provisioner_auth to main March 4, 2024 21:15
@Emyrk Emyrk force-pushed the stevenmasley/provisioner_org_scope branch from db381a4 to c11cfbc Compare March 4, 2024 21:17
organization_id = (SELECT id FROM organizations ORDER BY organizations.created_at ASC LIMIT 1 );

ALTER TABLE provisioner_daemons
ALTER COLUMN organization_id SET NOT NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need to explicitly put this stuff in a transaction? Otherwise a concurrent insert of a provisioner daemon could cause this ALTER to fail.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, by default all migrations run in a tx now.

#10966

provisioner_daemons
SET
-- Default to the first org
organization_id = (SELECT id FROM organizations ORDER BY organizations.created_at ASC 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.

it's an odd case, but this will fail if there is a provisioner daemon but no default org, which could happen if you start coderd on an older version (which creates in-memory provisioner daemons) but don't create the first user, and then migrate.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we need this PR in first: #12412

@@ -1239,10 +1239,18 @@ func (api *API) CreateInMemoryProvisionerDaemon(dialCtx context.Context, name st
}
}()

// All in memory provisioners will be apart of the default org for now.
//nolint:gocritic // in-memory provisioners are owned by system
defaultOrg, err := api.Database.GetDefaultOrganization(dbauthz.AsSystemRestricted(dialCtx))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you've already noticed that this will fail if the default organization hasn't been created. So think we need have a migration that creates a default org if none exists before we can have this.

Copy link
Member Author

@Emyrk Emyrk Mar 5, 2024

Choose a reason for hiding this comment

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

Yea, I will make sure this PR is merged first: #12412

@Emyrk Emyrk requested a review from spikecurtis March 6, 2024 13:40
@Emyrk Emyrk merged commit b5f866c into main Mar 6, 2024
@Emyrk Emyrk deleted the stevenmasley/provisioner_org_scope branch March 6, 2024 18:04
@github-actions github-actions bot locked and limited conversation to collaborators Mar 6, 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.

Org scoped provision daemons
2 participants