-
Notifications
You must be signed in to change notification settings - Fork 948
Next
Next commit
add user_status_changes table
- Loading branch information
commit 4cd66af5fbff7c29bdbefae36026305d785cbe8e
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
coderd/database/migrations/000279_user_status_changes.down.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- Drop the trigger first | ||
DROP TRIGGER IF EXISTS user_status_change_trigger ON users; | ||
|
||
-- Drop the trigger function | ||
DROP FUNCTION IF EXISTS record_user_status_change(); | ||
|
||
-- Drop the indexes | ||
DROP INDEX IF EXISTS idx_user_status_changes_changed_at; | ||
DROP INDEX IF EXISTS idx_user_status_changes_user_id; | ||
|
||
-- Drop the table | ||
DROP TABLE IF EXISTS user_status_changes; |
43 changes: 43 additions & 0 deletions
43
coderd/database/migrations/000279_user_status_changes.up.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
CREATE TABLE user_status_changes ( | ||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(), | ||
user_id uuid NOT NULL REFERENCES users(id), | ||
new_status user_status NOT NULL, | ||
changed_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
COMMENT ON TABLE user_status_changes IS 'Tracks the history of user status changes'; | ||
|
||
CREATE INDEX idx_user_status_changes_user_id ON user_status_changes(user_id); | ||
CREATE INDEX idx_user_status_changes_changed_at ON user_status_changes(changed_at); | ||
|
||
INSERT INTO user_status_changes ( | ||
user_id, | ||
new_status, | ||
changed_at | ||
) | ||
SELECT | ||
id, | ||
status, | ||
created_at | ||
FROM users | ||
WHERE NOT deleted; | ||
|
||
CREATE FUNCTION record_user_status_change() RETURNS trigger AS $$ | ||
BEGIN | ||
8000 | IF OLD.status IS DISTINCT FROM NEW.status THEN | |
INSERT INTO user_status_changes ( | ||
user_id, | ||
new_status | ||
) VALUES ( | ||
NEW.id, | ||
NEW.status | ||
); | ||
END IF; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
CREATE TRIGGER user_status_change_trigger | ||
BEFORE UPDATE ON users | ||
FOR EACH ROW | ||
EXECUTE FUNCTION record_user_status_change(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat(site): display user status history as an indication of license usage #16020
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
Uh oh!
There was an error while loading. Please reload this page.
feat(site): display user status history as an indication of license usage #16020
Changes from 1 commit
4cd66af
61b27bf
7cba28c
2d748c9
52620ce
6d15a32
b99468f
b204783
ce1bda5
734ff2b
737e63e
045e438
32aeb4d
1a2fde8
5b8fcac
4ac83aa
b23018a
adbc8aa
8bff303
1ceff06
94bb06a
d443a72
040086e
File 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.