succotash 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +14 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +116 -0
- data/Rakefile +6 -0
- data/VERSION +1 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/succotash/railtie.rb +11 -0
- data/lib/succotash/version.rb +3 -0
- data/lib/succotash.rb +8 -0
- data/lib/tasks/seed.rake +56 -0
- data/lib/tasks/succotash.rake +26 -0
- data/lib/templates/sample.yml +8 -0
- data/lib/templates/static.yml +7 -0
- data/succotash.gemspec +27 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d606ad6b450acc894db065927c310650dfad740f
|
4
|
+
data.tar.gz: f978dac7f191b7623cf67d83745e5fbf105c1930
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bd746f32677dcb4121cc9fd73d251a2097f183e68eb26cbe83a618cc176d78127530dd8811da352d692c7b58ea089e659bbbe3ee3ed7d7c18b20425089dc6f68
|
7
|
+
data.tar.gz: 5ccc4191837cf8452449197965f0b9328795be05b2088b9f26142e7c646510d0b095c74d52e6c6383f1c4d0446c1b07108dedfdaabf040422bc2ff3799a947ac
|
data/.editorconfig
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# top-most EditorConfig file
|
2
|
+
root = true
|
3
|
+
|
4
|
+
[*]
|
5
|
+
# all files should end with a new line
|
6
|
+
end_of_line = lf
|
7
|
+
insert_final_newline = true
|
8
|
+
|
9
|
+
# 2 space indentation
|
10
|
+
indent_style = space
|
11
|
+
indent_size = 2
|
12
|
+
|
13
|
+
# trim trailing white spaces
|
14
|
+
trim_trailing_whitespace = true
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 John Cleary
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# Succotash
|
2
|
+
|
3
|
+
A simple seeding strategy for your project which helps maintain and separate **static** and **sample** data.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'succotash'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install succotash
|
20
|
+
|
21
|
+
|
22
|
+
### Automatic configuration
|
23
|
+
```ruby
|
24
|
+
$ rake succotash:install
|
25
|
+
```
|
26
|
+
|
27
|
+
### Manual configuration
|
28
|
+
Create the following files
|
29
|
+
|
30
|
+
**db/seeds/static.yml**
|
31
|
+
```ruby
|
32
|
+
# list file names that needs to be included in the order required
|
33
|
+
# eg
|
34
|
+
# :static_seed_files:
|
35
|
+
# - customer_types.rb
|
36
|
+
# - error_codes.rb
|
37
|
+
|
38
|
+
:static_seed_files:
|
39
|
+
```
|
40
|
+
|
41
|
+
**db/seeds/sample.yml**
|
42
|
+
```ruby
|
43
|
+
# list file names that needs to be included in the order required
|
44
|
+
# eg
|
45
|
+
# :sample_seed_files:
|
46
|
+
# - user_seed.rb
|
47
|
+
# - test_file.rb
|
48
|
+
|
49
|
+
:sample_seed_files:
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
## Problem
|
55
|
+
- Inconsistent approach to seeding data on development, integration and staging causing confusion and a loss of productivity (for example when manually seeded data is lost after a drop+seed)
|
56
|
+
- Different approaches may be required for different kinds of seed data (sample seed, look-up table seed)
|
57
|
+
- No defined approach to migrating data when structure changes (even more important now that we are live)
|
58
|
+
|
59
|
+
These problems cost time for developers as they build local versions of services and each time they move services into integration, staging, acceptance and production.
|
60
|
+
|
61
|
+
## Definitions
|
62
|
+
|
63
|
+
##### Static Data
|
64
|
+
Data that is required by the system in order for the system to function correctly. We should assume that this is run against **production** after every release so it should be **idempotent**. It would typically contain lookup data, but it must not include sample users or example data.
|
65
|
+
|
66
|
+
##### Sample Data
|
67
|
+
Data that is required to demo the system or individual features. Typically this will be run after a db:reset (and after the seed). It should never be run against production and therefore does not have to be idempotent.
|
68
|
+
|
69
|
+
##### Idempotent
|
70
|
+
Doesn’t change anything if you run it more than once, or more formally: ‘denoting an element of a set which is unchanged in value when multiplied or otherwise operated on by itself.’)
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
## Usage
|
75
|
+
|
76
|
+
Both static and sample data.
|
77
|
+
```bash
|
78
|
+
$ rake db:seed
|
79
|
+
```
|
80
|
+
|
81
|
+
Static data only.
|
82
|
+
```bash
|
83
|
+
$ rake db:seed:static
|
84
|
+
```
|
85
|
+
|
86
|
+
Sample data only.
|
87
|
+
```bash
|
88
|
+
$ rake db:seed:sample
|
89
|
+
```
|
90
|
+
|
91
|
+
`test.rb` file in the `db/seeds/static` directory
|
92
|
+
```bash
|
93
|
+
$ rake db:seed:static:test
|
94
|
+
```
|
95
|
+
|
96
|
+
`test.rb` file in the `db/seeds/sample` directory
|
97
|
+
```bash
|
98
|
+
$ rake db:seed:sample:test
|
99
|
+
```
|
100
|
+
|
101
|
+
|
102
|
+
## Development
|
103
|
+
|
104
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
105
|
+
|
106
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
107
|
+
|
108
|
+
## Contributing
|
109
|
+
|
110
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/CreatekIO/succotash.
|
111
|
+
|
112
|
+
|
113
|
+
## License
|
114
|
+
|
115
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
116
|
+
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "succotash"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/succotash.rb
ADDED
data/lib/tasks/seed.rake
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# clear default db:seed task as want disable this behavior in favour of the
|
2
|
+
# db:static and db:sample tasks
|
3
|
+
Rake::Task['db:seed'].clear
|
4
|
+
|
5
|
+
namespace :db do
|
6
|
+
desc "Run db:seed:static and db:seed:sample"
|
7
|
+
task seed: %w{seed:static seed:sample} do
|
8
|
+
warn "[WARNING] `db/seed.rb` and it;s task `rake db:seed` have been disabled by the succotash gem. Please move seed data to db/static.rb or db/sample.rb".light_yellow if File.exist? Fine.join(Rails.root, 'db/seeds.rb')
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :seed do
|
12
|
+
|
13
|
+
def load_seed_namespace ns
|
14
|
+
# create top-level task (eg db:seed:static or db:seed:sample)
|
15
|
+
desc "Load #{ns} seed file"
|
16
|
+
task ns => :environment do
|
17
|
+
seed_list = YAML::load_file("#{Rails.root}/db/seeds/#{ns}.yml")["#{ns}_seed_files".to_sym] || []
|
18
|
+
seed_list.each do |file|
|
19
|
+
load_seed "#{Rails.root}/db/seeds/#{ns}/#{file}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
namespace ns do
|
24
|
+
FileList["#{Rails.root}/db/seeds/#{ns}/*.rb"].each do |seed_file|
|
25
|
+
task_name = File.basename(seed_file, '.rb')
|
26
|
+
|
27
|
+
desc "Load #{task_name} #{ns} seed file"
|
28
|
+
task task_name => :environment do
|
29
|
+
load_seed seed_file
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def load_seed seed_file
|
37
|
+
return if Rails.env == 'production'
|
38
|
+
if File.exist?(seed_file)
|
39
|
+
ActiveRecord::Base.transaction do
|
40
|
+
begin
|
41
|
+
puts "*** Seeding #{seed_file} ***".green
|
42
|
+
load seed_file
|
43
|
+
rescue => exception
|
44
|
+
warn exception.message.red
|
45
|
+
end
|
46
|
+
end
|
47
|
+
else
|
48
|
+
puts "#{seed_file} does not exist. Run `rake seed_runner:install` to create this or follow the README for manual install".red
|
49
|
+
puts "#{File.basename(seed_file, '.rb')} skipped"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
load_seed_namespace 'static'
|
54
|
+
load_seed_namespace 'sample'
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace :succotash do
|
2
|
+
desc "Create 'db/seeds/static.rb' and 'db/seeds/sample.rb'"
|
3
|
+
task :install do
|
4
|
+
spec = Gem::Specification.find_by_name 'succotash'
|
5
|
+
|
6
|
+
puts "*** Creating seed dirs ***".green
|
7
|
+
system("mkdir -p #{Rails.root}/db/seeds/{static,sample}") unless Dir.exist?("#{Rails.root}/db/seeds")
|
8
|
+
system("mkdir -p #{Rails.root}/db/seeds/static") unless Dir.exist?("#{Rails.root}/db/seeds/static")
|
9
|
+
system("mkdir -p #{Rails.root}/db/seeds/sample") unless Dir.exist?("#{Rails.root}/db/seeds/sample")
|
10
|
+
|
11
|
+
unless File.exist?("#{Rails.root}/db/seeds/static.yml")
|
12
|
+
system("cp #{spec.gem_dir}/lib/templates/static.yml #{Rails.root}/db/seeds/")
|
13
|
+
puts "*** Settings up static.rb ***".green
|
14
|
+
else
|
15
|
+
puts "*** static.rb already exists ***".yellow
|
16
|
+
end
|
17
|
+
|
18
|
+
unless File.exist?("#{Rails.root}/db/seeds/sample.yml")
|
19
|
+
system("cp #{spec.gem_dir}/lib/templates/sample.yml #{Rails.root}/db/seeds/")
|
20
|
+
puts "*** Settings up sample.rb ***".green
|
21
|
+
else
|
22
|
+
puts "*** sample.rb already exists ***".yellow
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/succotash.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'succotash/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "succotash"
|
8
|
+
spec.version = Succotash::VERSION
|
9
|
+
spec.authors = ["Hassan Khalid", "John Cleary"]
|
10
|
+
spec.email = ["dev@createk.io"]
|
11
|
+
|
12
|
+
spec.summary = "A simple seeding strategy for your project which helps maintain and separate static and demo data."
|
13
|
+
spec.description = "A simple seeding strategy for your project which helps maintain and separate static and demo data."
|
14
|
+
spec.homepage = "https://github.com/CreatekIO/succotash"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
spec.add_development_dependency "version", "~> 1.0.0"
|
26
|
+
spec.add_dependency "colorize", "0.7.7"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: succotash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hassan Khalid
|
8
|
+
- John Cleary
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.11'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.11'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: version
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.0.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.0.0
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: colorize
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.7.7
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 0.7.7
|
84
|
+
description: A simple seeding strategy for your project which helps maintain and separate
|
85
|
+
static and demo data.
|
86
|
+
email:
|
87
|
+
- dev@createk.io
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- .editorconfig
|
93
|
+
- .gitignore
|
94
|
+
- .rspec
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- VERSION
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- lib/succotash.rb
|
103
|
+
- lib/succotash/railtie.rb
|
104
|
+
- lib/succotash/version.rb
|
105
|
+
- lib/tasks/seed.rake
|
106
|
+
- lib/tasks/succotash.rake
|
107
|
+
- lib/templates/sample.yml
|
108
|
+
- lib/templates/static.yml
|
109
|
+
- succotash.gemspec
|
110
|
+
homepage: https://github.com/CreatekIO/succotash
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.4.8
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: A simple seeding strategy for your project which helps maintain and separate
|
134
|
+
static and demo data.
|
135
|
+
test_files: []
|