Giter VIP home page Giter VIP logo

sequel-seed's Introduction

Sequel::Seed Gem Version Build Status codecov Codacy Badge

A Sequel extension to make seeds/fixtures manageable like migrations

Usage

Create a seed file (eg. /path/to/seeds/20150928000000_initial_seed.rb)

Sequel.seed(:development, :test) do # Applies only to "development" and "test" environments
  def run
    [
      ['USD', 'United States dollar'],
      ['BRL', 'Brazilian real']
    ].each do |abbr, name|
      Currency.create abbr: abbr, name: name
    end
  end
end

Set the environment

Sequel::Seed.setup :development

Load the extension

require 'sequel'
require 'sequel/extensions/seed'

Sequel.extension :seed

Apply the seeds/fixtures

DB = Sequel.connect(...)
Sequel::Seeder.apply(DB, "/path/to/seeds")

For more information, please check the project website.

Limitations

  • JSON and YAML files don't work with associations
  • Only timestamped seed/fixture files

What's next?

Work with Model's associations inside JSON & YAML files

Support

If you need any help (or have found any bug 🐞), please post it on /issues. Thank you!

License

MIT License Β© Ewerton Carlos Assis

sequel-seed's People

Contributors

dependabot[bot] avatar earaujoassis avatar olleolleolle avatar onewheelskyward avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

sequel-seed's Issues

Can’t run seed

I'm getting the following error:

LoadError: cannot load such file -- sequel/extensions/seed

this happens even after I initialize sequel-seed like so:

require 'sequel'
require 'sequel/extensions/seed'

YAML seeds fail when Sequel::Model subclass is autoloaded

If the class specified in a YAML seed is autoloaded (but not yet loaded), Sequel::Seeder.apply will fail with the following error:

NameError: undefined local variable or method `class_name' for #<#<Class:0x007fddad16c4b0>:0x007fddaf4f7c68>

Using Arrays in JSON migrations (type mismatch)

NotificationTemplate.create
"supported_devices": [1,2,3] ;
end# notification do

it is showing this error
rake aborted!
Sequel::DatabaseError: PG::DatatypeMismatch: ERROR: column "supported_devices" is of type text[] but expression is of type record
LINE 1: ..._id}', true, 'am_new_owner_lead_email', NULL, '', (1, 2, 3),...

HINT: You will need to rewrite or cast the expression.

then i have replace [1,2,3] with
Sequel.pg_array([1,2,3],:text)

error
rake aborted!
Sequel::DatabaseError: PG::InvalidTextRepresentation: ERROR: malformed array literal: "[1, 2, 3]"
LINE 1: ..._id}', true, 'am_new_owner_lead_email', NULL, '', '[1, 2, 3]...

DETAIL: Missing "]" after array dimensions.

my model class is

require 'sequel'
require 'pg'
require 'sequel/extensions/seed'
Sequel.extension :seed
DB = Sequel.connect(ENV['DATABASE_URL'])

DB.extension :pg_array

class NotificationTemplate < Sequel::Model
dataset = DB[:notification_templates]
end

i am trying to run using rake db:migrate

Access to Database

Hello! First off, thanks for putting this together. Very cool.

I am working on a brand new rails 6 rc2 api and I have replaced ActiveRecord with Sequel. For this first project I am trying to not use any models. For example, this is what I have in a seed:

def run
    plan_id = IdUtils.new_id
    db = DatabaseUtils.db_connection
    db[:plans].insert(id: plan_id, name: 'testing')
end

I am wondering if I have access to the database within your framework, vs going out to my db utils module.

Thanks again!

Target version support

Hi!
Sequel::Seeder doesn't support target version?
For example, Sequel::Migrator:

Sequel::Migrator.run(
  DB,
  migrations_dir,
  target: args[:version].to_i
)

seed_hash_environment is not a local variable

Looks like a minor paste mishap.

NameError: undefined local variable or method `seed_hash_environment' for #<#<Class:0x56aaaecd>:0x5e01a982>
        apply_seed_hash at /Users/olle/.rvm/gems/jruby-1.7.23/gems/sequel-seed-0.3.1/lib/sequel/extensions/seed.rb:128
  apply_seed_descriptor at /Users/olle/.rvm/gems/jruby-1.7.23/gems/sequel-seed-0.3.1/lib/sequel/extensions/seed.rb:115
                   each at org/jruby/RubyArray.java:1613

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.