- Notifications
You must be signed in to change notification settings - Fork1.1k
feat: persist prebuild definitions on template import#16951
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
5ecc277bc5f4f448c5372b16d1262c255428e491d8514fdbf390a1fd07e9613a07c2b2300e80fb7882378122595bfb7c286639167769ae1de7e9c2739360478bdcafb412d19851773ec23773c2bc3ff44baa3076ed14fb33cc74fbfc32154d7b4ec4e8b53f79df6554ccc309eee1f16ad040ddd83a6722cd707100f3bda0a7c7cd297cc4ff4d59039205d6afe489e1b1b2968620470e46fc18897b9c8cee189a0b692c0e5f747db03166a42aa6b490bc4e7d2f167b928fd34ab7a8ec49a64d661865998bc787cd2bd38603097f9c34cfdd6f4a34d528d9cd45f870d7e18ad9314667171a26c094bf4ab53a84b1bb6ed4121e8b15022312f414540a555c41ba9d09b75761e86f61419df06589221b15b97add656a7508b244e1f585d7d4f1b943f82b95d8de71a87933a798cfa1dc87f457c17fcdFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| -- Remove system user from organizations | ||
| DELETE FROM organization_members | ||
| WHERE user_id = 'c42fdf75-3097-471c-8c33-fb52454d81c0'; | ||
| -- Drop triggers first | ||
| DROP TRIGGER IF EXISTS prevent_system_user_updates ON users; | ||
| DROP TRIGGER IF EXISTS prevent_system_user_deletions ON users; | ||
| -- Drop function | ||
| DROP FUNCTION IF EXISTS prevent_system_user_changes(); | ||
| -- Delete system user | ||
| DELETE FROM users | ||
| WHERE id = 'c42fdf75-3097-471c-8c33-fb52454d81c0'; | ||
| -- Drop index | ||
| DROP INDEX IF EXISTS user_is_system_idx; | ||
| -- Drop column | ||
| ALTER TABLE users DROP COLUMN IF EXISTS is_system; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| ALTER TABLE users | ||
| ADD COLUMN is_system bool DEFAULT false; | ||
| CREATE INDEX user_is_system_idx ON users USING btree (is_system); | ||
| COMMENT ON COLUMN users.is_system IS 'Determines if a user is a system user, and therefore cannot login or perform normal actions'; | ||
| -- TODO: tried using "none" for login type, but the migration produced this error: 'unsafe use of new value "none" of enum type login_type' | ||
| -- -> not sure why though? it exists on the login_type enum. | ||
| INSERT INTO users (id, email, username, name, created_at, updated_at, status, rbac_roles, hashed_password, is_system, login_type) | ||
| VALUES ('c42fdf75-3097-471c-8c33-fb52454d81c0', 'prebuilds@system', 'prebuilds', 'Prebuilds Owner', now(), now(), | ||
| 'active', '{}', 'none', true, 'password'::login_type); | ||
| -- Create function to check system user modifications | ||
| CREATE OR REPLACE FUNCTION prevent_system_user_changes() | ||
| RETURNS TRIGGER AS | ||
| $$ | ||
| BEGIN | ||
| IF OLD.is_system = true THEN | ||
| RAISE EXCEPTION 'Cannot modify or delete system users'; | ||
| END IF; | ||
| RETURN OLD; | ||
| END; | ||
| $$ LANGUAGE plpgsql; | ||
| -- Create trigger to prevent updates to system users | ||
| CREATE TRIGGER prevent_system_user_updates | ||
| BEFORE UPDATE ON users | ||
| FOR EACH ROW | ||
| WHEN (OLD.is_system = true) | ||
| EXECUTE FUNCTION prevent_system_user_changes(); | ||
| -- Create trigger to prevent deletion of system users | ||
| CREATE TRIGGER prevent_system_user_deletions | ||
| BEFORE DELETE ON users | ||
| FOR EACH ROW | ||
| WHEN (OLD.is_system = true) | ||
| EXECUTE FUNCTION prevent_system_user_changes(); | ||
| -- TODO: do we *want* to use the default org here? how do we handle multi-org? | ||
| WITH default_org AS (SELECT id | ||
| FROM organizations | ||
| WHERE is_default = true | ||
| LIMIT 1) | ||
| INSERT | ||
| INTO organization_members (organization_id, user_id, created_at, updated_at) | ||
| SELECT default_org.id, | ||
| 'c42fdf75-3097-471c-8c33-fb52454d81c0', -- The system user responsible for prebuilds. | ||
| NOW(), | ||
| NOW() | ||
| FROM default_org; |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.