-
Notifications
You must be signed in to change notification settings - Fork 66
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
Create user_actions and user_action_events tables #20349
Changes from 1 commit
8f606cb
ebbbb85
3ea353e
8d0d422
95b2554
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class CreateUserActionEvents < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :user_action_events do |t| | ||
t.string :details, null: false | ||
t.timestamps null: false | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class CreateUserActions < ActiveRecord::Migration[7.2] | ||
def change | ||
# Create the enum type first | ||
create_enum :user_action_status, ['initial', 'success', 'error'] | ||
|
||
create_table :user_actions, id: :uuid do |t| | ||
# Core fields | ||
t.uuid :acting_user_account_id, null: false | ||
t.uuid :subject_user_account_id, null: false | ||
t.references :user_action_event, null: false, foreign_key: { validate: 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. You don't need to set t.references :user_action_event, null: false, foreign_key: true 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. Good point! Removed |
||
t.enum :status, enum_type: :user_action_status, default: 'initial', null: false, index: true | ||
|
||
# Additional columns from ticket | ||
t.boolean :user_verified, default: false, null: false | ||
t.string :ip_address | ||
t.jsonb :device_info | ||
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 believe this should be a 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. Changed |
||
|
||
t.timestamps null: false | ||
end | ||
|
||
add_foreign_key :user_actions, :user_accounts, column: :acting_user_account_id, validate: false | ||
add_foreign_key :user_actions, :user_accounts, column: :subject_user_account_id, validate: false | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class ValidateUserActionsForeignKeys < ActiveRecord::Migration[7.2] | ||
def change | ||
validate_foreign_key :user_actions, :user_accounts, column: :acting_user_account_id | ||
validate_foreign_key :user_actions, :user_accounts, column: :subject_user_account_id | ||
validate_foreign_key :user_actions, :user_action_events | ||
end | ||
end | ||
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. This file is missing an end of file new line 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 believe it's fixed now. Also, I am going to add this to Layout/TrailingEmptyLines:
Enabled: true
EnforcedStyle: final_newline 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. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use
references
here and then remove theadd_foreign_key
s at the end. This will make strong migrations happy and then we won't need the extra migrations to validate an empty table. This will also add an index to these columns, which we'll need.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I've updated to use
references
.