-
Notifications
You must be signed in to change notification settings - Fork 4
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
bulk add opportunities #341
Conversation
!m @dmtroyer |
Over to you, @dmtroyer! :-) |
!m @dmtroyer |
Currently, the csv parsing logic expects a header in the csv which defines the names of the fields being uploaded in the order listed in the header.
|
Getting back into this, hitting Opportunity.transaction do
CSV.parse(params[:csv].read, headers: true) do |row|
row['resource_sub_type_id'] = ResourceSubType.find_by_name(row.delete('resource_sub_type')).id
@opportunities.push(Opportunity.create!(row.to_h))
end
end |
That's with the test data from above at #341 (comment). Looks like 266ce91 added an expectation for the CSV structure ... |
(For my notes: I found the database config in learn_dev=# select * from resource_sub_types;
┌────┬───────┬──────────────────┐
│ id │ name │ resource_type_id │
├────┼───────┼──────────────────┤
│ 1 │ Event │ 1 │
└────┴───────┴──────────────────┘
(1 row)
learn_dev=# ) |
I've started a to-do list in the PR description. |
There are some fields that are required, |
I'm trying to understand the Opportunity model and the opportunities table. They don't appear to sync up. The latter has way more fields than the former. class Opportunity < ActiveRecord::Base
has_many :opportunity_instances
belongs_to :organizer
has_one :after_this, class_name: "Opportunity", foreign_key: "after_this_id"
has_one :before_this, class_name: "Opportunity", foreign_key: "before_this_id"
belongs_to :resource_sub_type
has_one :resource_type, through: :resource_sub_type
validates :resource_sub_type, presence: true
def active_model_serializer
OpportunitySerializer
end
end Null display is "¤".
Line style is unicode.
Border style is 2.
Table "public.opportunities"
┌───────────────────────┬─────────────────────────────┬────────────────────────────────────────────────────────────┐
│ Column │ Type │ Modifiers │
├───────────────────────┼─────────────────────────────┼────────────────────────────────────────────────────────────┤
│ id │ integer │ not null default nextval('opportunities_id_seq'::regclass) │
│ name │ character varying │ │
│ address │ text │ │
│ description │ text │ │
│ registration_url │ character varying │ │
│ location_name │ character varying │ │
│ registration_deadline │ timestamp without time zone │ │
│ program_type │ character varying │ │
│ logo_url │ character varying │ │
│ starts_at │ timestamp without time zone │ │
│ ends_at │ timestamp without time zone │ │
│ online_address │ character varying │ │
│ zipcode │ character varying │ │
│ city │ character varying │ │
│ state │ character varying │ │
│ is_online │ boolean │ │
│ hide_reason │ character varying │ │
│ hide │ boolean │ │
│ contact_name │ character varying │ │
│ contact_email │ character varying │ │
│ contact_phone │ character varying │ │
│ price_level │ integer │ │
│ min_age │ integer │ │
│ max_age │ integer │ │
│ extra_data │ text │ │
│ created_at │ timestamp without time zone │ not null │
│ updated_at │ timestamp without time zone │ not null │
│ organizer_id │ integer │ │
│ topic_id │ integer │ │
│ after_this_id │ integer │ │
│ before_this_id │ integer │ │
│ badge_class_id │ character varying │ │
│ resource_sub_type_id │ integer │ │
└───────────────────────┴─────────────────────────────┴────────────────────────────────────────────────────────────┘
Indexes:
"opportunities_pkey" PRIMARY KEY, btree (id)
"index_opportunities_on_after_this_id" btree (after_this_id)
"index_opportunities_on_before_this_id" btree (before_this_id)
"index_opportunities_on_organizer_id" btree (organizer_id)
"index_opportunities_on_resource_sub_type_id" btree (resource_sub_type_id)
"index_opportunities_on_topic_id" btree (topic_id)
Foreign-key constraints:
"fk_rails_6d4b8f5561" FOREIGN KEY (topic_id) REFERENCES topics(id) |
Okay, noted in to-do. |
@dmtroyer Do we have a test suite? How do I run it? |
|
Rails is cheeky like that, it dynamically creates default getter and setters for attributes defined in the schema. So, if you're cool with the defaults they don't have to be explicitly defined in the model. |
Okay, thanks for the pointer.
|
How is this information encoded? I only see three out of 33 columns in the schema that are |
A couple of different ways:
|
@dmtroyer I only see one validated (required) field in The backtrace at #341 (comment) seems to indicate that |
@whit537 All correct. Field requirement and validation has not been completely flushed out. |
Okay! |
I'm gonna pull @timothyfcook over to make some decisions about required fields for the CSV upload. |
The word from @timothyfcook:
If |
Aren't there supposed to be gems for everything? Isn't that why we use Rails? Let's go look! :-) |
validates :registration_deadline, presence: true | ||
validates :starts_at, presence: true | ||
validates :ends_at, 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.
dat validation 👍
@whit537 thought I'd help out a little with the uniqueness constraint on |
Blam. Thanks, @dmtroyer. I was just about to ask you for help! :-) |
And with that, I'm out for the rest of the week. Heading to New York for gratipay/inside.gratipay.com#384 this weekend. See you next week! :-) |
@whit537 have fun! 🚌 🌆 💵 |
/me back ... |
c33b567
to
13d60de
Compare
Rebased on master. Former head was c33b567. |
Okay! I think this is ready to merge. Waddya think, @dmtroyer @timothyfcook? :-) |
I'll let @dmtroyer sign off on this one |
Waddya say, @dmtroyer? :-) |
Will do sometime today! On Fri, Nov 27, 2015, 10:25 Chad Whitacre [email protected] wrote:
|
1010d72
to
565e801
Compare
oops, unsure what the previous head was. sorry, seems to be OK. I'll probably squash it before I merge it, anyhow... |
4231420
to
bf58481
Compare
bulk add opportunities via csv
!m @dmtroyer |
Closes #338.
To-do
name