-
Notifications
You must be signed in to change notification settings - Fork 69
Dashboard Events #348
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
Dashboard Events #348
Conversation
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.
Nice POC! 💪
app/models/event.rb
Outdated
|
||
private | ||
|
||
# Validates that only one resourece id is set |
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.
s/resourece/resource
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.
Looking pretty good! tests and 👍
app/models/event.rb
Outdated
belongs_to :member | ||
belongs_to :transfer | ||
|
||
validates :action, inclusion: { :in => ACTIONS }, presence: true |
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.
🔥 that #️⃣ 🚀
00776b2
to
d746b62
Compare
db/schema.rb
Outdated
@@ -76,6 +76,9 @@ | |||
add_index "documents", ["documentable_id", "documentable_type"], name: "index_documents_on_documentable_id_and_documentable_type", using: :btree | |||
add_index "documents", ["label"], name: "index_documents_on_label", using: :btree | |||
|
|||
# Could not dump table "events" because of following StandardError | |||
# Unknown type 'action_enum' for column 'action' | |||
|
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.
db/schema.rb
and start using db/structure.sql
, let's talk about it
cc/ @sauloperez
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.
Another solution is to use the AR built in enum, basically storing an integer
instead of a string
(classic Rails approach with validation only at model level) or ENUM
(DB check level I'm proposing)
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.
I think we are safe enough using AR enum :)
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.
There is another option using AR enum
storing integer
as I said AND adding check inclusion instead of PG enum
. Will propose this option as it seems a good tradeoff to me
transfer_id integer REFERENCES transfers, | ||
created_at timestamp without time zone, | ||
updated_at timestamp without time zone, | ||
CHECK( |
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.
I would only do this in SQL by means of an ALTER TABLE. This way we keep the rest using Rails' DSL, which might be easier to read for other devs.
nice feature here team 👏 🔝 As @mllocs and @sauloperez pointed out, I'd stick with simpler solutions like: a) string + model validation (inclusion) I think both options give us enough data integrity and seems an approach more easy to follow for more people. |
I have been bitten badly by cases of inconsistent data representation. Even
at the cost of some more effort from the data integrity point of view, it
is always much better to see the same from sql and from ruby. I’d vote for
either Postgres enums (that appear as strings to the client) or just
strings with validation. The former can also suffer from the same issues as
ruby-to-sql enumerations in case of adding new items.
El El dom, 13 may 2018 a las 13:41, Marc Anguera Insa <
notifications@github.com> escribió:
… nice feature here team 👏 🔝
As @mllocs <https://github.com/mllocs> and @sauloperez
<https://github.com/sauloperez> pointed out, I'd stick with simpler
solutions like:
a) string + model validation (inclusion)
b) AR enum
I think both options give us enough data integrity and seems an approach
more easy to follow for more people.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#348 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAdG394H_6iE8ALat64c7SdDSvmaZPhrks5tyBvrgaJpZM4Tt37H>
.
|
afcb387
to
43a0f4f
Compare
member_id integer REFERENCES members, | ||
transfer_id integer REFERENCES transfers, | ||
created_at timestamp without time zone, | ||
updated_at timestamp without time zone, |
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.
I left I comment about this already but it got collapsed. What about having the regular create_table and then an alter table for these checks that can't be done with AR? I think this would make it a bit more clear that we specify things AR does not provide and perhaps a bit more readable.
@@ -0,0 +1,39 @@ | |||
# This migration does not use Rails ActiveRecord ORM DSL since | |||
# it doesn't provide data integrity (foreign key) for polymorphic models. |
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.
I'm not sure I fully understand what you mean.
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.
Read the article 😂
TestedCRUD
|
WAT
Using the Persisters to create Events. See #347.
Test