Giter Club home page Giter Club logo

planter's Introduction

planter's People

Contributors

dependabot[bot] avatar evanthegrayt avatar firegamer3 avatar paranormalhacktivity avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

planter's Issues

Dependency persistance

"If you manually run docker-compose run app bundle install, but then docker system prune, the newly installed gems don’t persist unless you build. Maybe this is expected Docker behavior though?" - @evanthegrayt

Simplify seeding from parent

There's no need to create the record through the parent's association. Just pluck the ids of the parent model.

The user should just pass the name of the belongs_to association in the model. Then, the parent model, foreign key, and primary key can all be determined by doing the following.

model.constantize.reflect_on_association(parent).options

Add generators

rails g planter should generate the files/directories needed for the plugin to run.

raise: false option

Currently, all records are created with first_or_create!. It might be worth having a raise: false option in the seeding_method macro that would use first_or_create (no bang).

Tests for generators

Currently, we have to test generators manually. This should be part of the automated test suite.

Remove default erb trim_mode but allow user to configure

'<>' trim mode default for ERB is problematic for rows that have erb at beginning and end of row. We should remove the trim mode default, but allow an option to be passed that sets it.

Allowed options should be

%  enables Ruby code processing for lines beginning with %
<> omit newline for lines starting with <% and ending in %>
>  omit newline for lines ending in %>
-  omit blank lines ending in -%>

Add seeding_method option to generator

Add a way to specify
rails generate planter:seeder users --csv
rails generate planter:seeder users --data_array
rails generate planter:seeder users --custom
Depending on what's passed, the generator adds the correct text. The --csv option will also add the csv file, and add the field names as the headers, pulled from that table.

Migrations in docker

Currently, if I make a migration for the dummy project, I have to docker-compose run app bash, cd test/dummy, and run bin/rails db:migrate. Surely there's a way to do this from docker-compose.yml. I tried adding && cd test/dummy && bin/rails db:migrate to the command, but it didn't seem to work.

Way to specify which fields to find by

Add the ability to specify which columns to search by, and the rest will be used in during the creation if it doesn't already exist.

Example:

# users_seeder.rb
seeding_method :csv, unique_columns: %i[username email]

Assuming the CSV contains the following

username,email,bio
evanthegrayt,[email protected],I'm a developer

The seeder would then do User.where(username: 'evanthegrayt', email: '[email protected]').first_or_create!(bio: "I'm a developer")

Also look into using these methods: create_with and find_or_create_by.

Add progress bar.

I've seen @hkn34 implement a nice progress bar in some of our work projects. This feature would be a great addition.

There should be a config option to enable/disable it. Probably default to true.

Planter.configure do |config|
  config.progress_bar = true
end

It would also be nice to have a flag for the command line that can also enable/disable it at runtime, in case you want to change it for one run only. It would be a pain to edit the initializer every time. If not a flag, than an environmental variable?

rails planter:seed --progress
# or
rails planter:seed PROGRESS=true

Add CONTRIBUTING.md

Add contribution guidelines so people know how to build in docker and run tests.

Option to transform null

Currently, create_records will transform "NULL" to nil, but create_records_from_parent doesn't. No should be the default, but we should add a transform_null: true option to seeding_method.

Planter.seed shouldn't cause rails to abort

If someone was to add Planter.seed into db/seeds.rb and they didn't populate config.seeders in initializers/planter.rb this wowuld cause rails to abort, maybe a warning message should be shown instead?

CSV with ERB

User should be able to specify use ERB, or put .csv.erb as the filetype.

seeding_method :standard_csv, erb: true

Or name the file user.csv.erb

Finish readme

More examples of seeding_method options should be in the readme.

Only put native columns in where

When seeding people from csv and phone belongs to another table(contact_informations), then we should be able to detect what can be searched for in the Person.where query.

first_name,last_name,phone
Evan,Gray,123-456-7890
Person.where(first_name: 'Evan', last_name: 'Gray').first_or_create!(phone: '123-456-7890')

Add rake task

People may wish to keep db:seed task separate from planter. We should add our own task.

Add column transformations

When importing from CSV, there are often cases where the value needs to be manipulated in some form. I solved this problem in a project at work by adding a COLUMN_TRANSFORMATIONS hash. Basically, you define this hash in your seeder, where the keys are the column name, and the values are lambdas to be run on the value from the CSV (which is the argument to the lambda).

For example, if you have a column called time, and it's a string (always, because it's a CSV) that needs to be converted to a date object, and a field called transportation_needed that's 'yes' or 'no' in the CSV, but it needs to be a boolean, you can define a hash like so.

  COLUMN_TRANSFORMATIONS = {
    time: ->(v) { DateTime.strptime(v, '%m/%d/%Y %I:%M:%S %p') },
    transportation_needed: ->(v) { v[0].upcase == 'Y' }
  }.freeze

Then, when the seeder runs, if a transformation exists for the current column, it will be automatically transformed before it's imported via a map.

Add way to ignore fields in csv.

We're not always in control of csv exports, and sometimes they contain columns that aren't in the table being seeded. We need a way to either determine what the valid fields are, or let the user specify which ones to exclude.

Allow erb.csv or csv.erb in file name

When deciding whether to use erb when seeding from csv, the order currently matters. We should change the regex to

/\.erb(?:.csv)?$/

This will allow for .csv.erb OR .erb.csv to be the file extension.

Specifying number_of_records on a seeder appears to not work

Given

class PropertiesSeeder < Planter::Seeder
  seeding_method :data_array, number_of_records: 4, parent: :user

  def data
    [{
      street_1: Faker::Address.street_address,
      city: Faker::Address.city,
      state: Faker::Address.state_abbr,
      zip: Faker::Address.zip
    }]
  end
end

it appears that it will not seed more than one record per parent.
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.