ghost-seeder 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ghost-seeder.gemspec +39 -0
- data/lib/ghost/seeder.rb +6 -0
- data/lib/ghost/seeder/ar_models.rb +21 -0
- data/lib/ghost/seeder/db_connection.rb +53 -0
- data/lib/ghost/seeder/logger.rb +34 -0
- data/lib/ghost/seeder/models/generic_seed.rb +74 -0
- data/lib/ghost/seeder/models/generic_seed/yaml_bindings.rb +42 -0
- data/lib/ghost/seeder/models/post_tags_seed.rb +38 -0
- data/lib/ghost/seeder/models/posts_seed.rb +26 -0
- data/lib/ghost/seeder/models/settings_seed.rb +41 -0
- data/lib/ghost/seeder/models/tags_seed.rb +22 -0
- data/lib/ghost/seeder/monkey_patch_sqlite3.rb +13 -0
- data/lib/ghost/seeder/runner.rb +60 -0
- data/lib/ghost/seeder/tasks/db.rb +22 -0
- data/lib/ghost/seeder/version.rb +5 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c2b69d6c521290ff1914d9076db5500f11156354
|
4
|
+
data.tar.gz: 0145efeafd3e6770b5fb443336ccf299ff5cd8ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: db9caa0b3bae4efd34164e04514d97883d7c354311372ef7b70bd0312c45bd419dfde2d837a7146e966afddf10a8b603826f8631345834ebc159846f525e2799
|
7
|
+
data.tar.gz: 7f8c893c437cd56b4ec103abc0addc9443a85f3eea646e51f498d0c47a22e05ed2d38fcca222763fa9222234966560e4b20f04987823be7d4887911671fe153e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at a@macool.me. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 noggalito
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Ghost::Seeder
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ghost/seeder`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ghost-seeder'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ghost-seeder
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ghost-seeder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ghost/seeder"
|
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
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ghost/seeder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ghost-seeder"
|
8
|
+
spec.version = Ghost::Seeder::VERSION
|
9
|
+
spec.authors = ["Mario Andrés Correa"]
|
10
|
+
spec.email = ["a@macool.me"]
|
11
|
+
|
12
|
+
spec.summary = %q{Seeding ghost's DB}
|
13
|
+
spec.homepage = "https://github.com/noggalito/ghost-seeder"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_dependency "rake", "~> 11.3"
|
33
|
+
spec.add_dependency "faker", "~> 1.6"
|
34
|
+
spec.add_dependency "colorize", "~> 0.8"
|
35
|
+
spec.add_dependency "activerecord", "~> 4.2"
|
36
|
+
|
37
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
38
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
39
|
+
end
|
data/lib/ghost/seeder.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "active_record"
|
2
|
+
|
3
|
+
class ActiveRecord::Base
|
4
|
+
self.inheritance_column = nil
|
5
|
+
end
|
6
|
+
|
7
|
+
class Tag < ActiveRecord::Base
|
8
|
+
end
|
9
|
+
|
10
|
+
class Post < ActiveRecord::Base
|
11
|
+
end
|
12
|
+
|
13
|
+
class User < ActiveRecord::Base
|
14
|
+
end
|
15
|
+
|
16
|
+
class Setting < ActiveRecord::Base
|
17
|
+
end
|
18
|
+
|
19
|
+
class PostTag < ActiveRecord::Base
|
20
|
+
self.table_name = "posts_tags"
|
21
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "active_record"
|
2
|
+
|
3
|
+
module Ghost
|
4
|
+
module Seeder
|
5
|
+
class DbConnection
|
6
|
+
def initialize(environment)
|
7
|
+
@environment = environment
|
8
|
+
configure!
|
9
|
+
end
|
10
|
+
|
11
|
+
def connect!
|
12
|
+
ActiveRecord::Base.establish_connection(
|
13
|
+
@connection_options
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def disconnect!
|
18
|
+
ActiveRecord::Base.connection.disconnect!
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def configure!
|
24
|
+
case @environment
|
25
|
+
when "development"
|
26
|
+
@db_gem = "sqlite3"
|
27
|
+
require(@db_gem)
|
28
|
+
monkey_patch_sqlite3!
|
29
|
+
@connection_options = {
|
30
|
+
adapter: @db_gem,
|
31
|
+
database: Dir.pwd + "/content/data/ghost-dev.db"
|
32
|
+
}
|
33
|
+
else
|
34
|
+
@db_gem = "pg"
|
35
|
+
require(@db_gem)
|
36
|
+
db = URI.parse(ENV.fetch("DATABASE_URL"))
|
37
|
+
@connection_options = {
|
38
|
+
host: db.host,
|
39
|
+
encoding: "utf8",
|
40
|
+
username: db.user,
|
41
|
+
password: db.password,
|
42
|
+
database: db.path[1..-1],
|
43
|
+
adapter: db.scheme == "postgres" ? "postgresql" : db.scheme
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def monkey_patch_sqlite3!
|
49
|
+
require "ghost/seeder/monkey_patch_sqlite3"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "colorize"
|
2
|
+
|
3
|
+
module Ghost
|
4
|
+
module Seeder
|
5
|
+
class Logger
|
6
|
+
class << self
|
7
|
+
COLORS = {
|
8
|
+
info: :white,
|
9
|
+
warn: :yellow,
|
10
|
+
success: :green
|
11
|
+
}
|
12
|
+
|
13
|
+
%w(
|
14
|
+
warn
|
15
|
+
info
|
16
|
+
success
|
17
|
+
).map(&:to_sym).each do |level|
|
18
|
+
define_method level do |msg, *details|
|
19
|
+
color = COLORS[level]
|
20
|
+
log(
|
21
|
+
String(level).upcase.colorize(color),
|
22
|
+
String(msg),
|
23
|
+
String(details.join(" ")).colorize(:blue)
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def log(*args)
|
29
|
+
puts "[#{Time.now}] #{args.join(" ")}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "yaml"
|
3
|
+
require "ghost/seeder/models/generic_seed/yaml_bindings"
|
4
|
+
|
5
|
+
module Ghost
|
6
|
+
module Seeder
|
7
|
+
module Models
|
8
|
+
class GenericSeed
|
9
|
+
class << self
|
10
|
+
def perform_queries
|
11
|
+
seeds.each do |record|
|
12
|
+
new(record).seed!
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def wipe_records!
|
17
|
+
Logger.warn "wiping", klass
|
18
|
+
klass.destroy_all
|
19
|
+
end
|
20
|
+
|
21
|
+
def load_fixtures(identifier)
|
22
|
+
YAML.load(
|
23
|
+
ERB.new(
|
24
|
+
File.read(
|
25
|
+
"./config/seed/fixtures/#{identifier}.yml"
|
26
|
+
)
|
27
|
+
).result(YamlBindings.new.helper)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def seeds
|
32
|
+
load_fixtures klass.to_s.downcase.pluralize
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_reader :record, :attributes
|
37
|
+
|
38
|
+
def initialize(attributes)
|
39
|
+
@attributes = attributes
|
40
|
+
# allow calling hash attributes as methods
|
41
|
+
@record = OpenStruct.new(attributes)
|
42
|
+
end
|
43
|
+
|
44
|
+
def seed!
|
45
|
+
if record_exists?
|
46
|
+
Logger.info "#{self.class} exists:", record_slug
|
47
|
+
raise "#{record_slug} not expected to exist!" if Runner.wipe_db?
|
48
|
+
else
|
49
|
+
create_record!
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def first_user
|
56
|
+
@first_user ||= User.first
|
57
|
+
end
|
58
|
+
|
59
|
+
def record_exists?
|
60
|
+
self.class.klass.where(slug: record.slug).exists?
|
61
|
+
end
|
62
|
+
|
63
|
+
def record_slug
|
64
|
+
record.slug
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_record!
|
68
|
+
self.class.klass.create(attributes_for_create)
|
69
|
+
Logger.success self.class, record_slug
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "securerandom"
|
2
|
+
require "faker"
|
3
|
+
|
4
|
+
module Ghost
|
5
|
+
module Seeder
|
6
|
+
module Models
|
7
|
+
class GenericSeed
|
8
|
+
class YamlBindings
|
9
|
+
def helper
|
10
|
+
binding
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def uuid
|
16
|
+
SecureRandom.uuid
|
17
|
+
end
|
18
|
+
|
19
|
+
def lipsum
|
20
|
+
Faker::Hipster.paragraph(5, true, 5)
|
21
|
+
end
|
22
|
+
|
23
|
+
def lipsum_small
|
24
|
+
Faker::Hipster.paragraph(2, true, 2)
|
25
|
+
end
|
26
|
+
|
27
|
+
# def lipsum_html
|
28
|
+
# Faker::Lorem.paragraph(5, true, 5)
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# def lipsum_small
|
32
|
+
# Faker::Lorem.sentence
|
33
|
+
# end
|
34
|
+
|
35
|
+
def fake_sentence
|
36
|
+
Faker::Hipster.sentence
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "ghost/seeder/models/generic_seed"
|
2
|
+
|
3
|
+
module Ghost
|
4
|
+
module Seeder
|
5
|
+
module Models
|
6
|
+
class PostTagsSeed < GenericSeed
|
7
|
+
def self.klass
|
8
|
+
PostTag
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.seeds
|
12
|
+
load_fixtures("posts_tags").map do |post_tag|
|
13
|
+
tag = Tag.find_by! slug: post_tag["tag_slug"]
|
14
|
+
post = Post.find_by! slug: post_tag["post_slug"]
|
15
|
+
{
|
16
|
+
tag_id: tag.id,
|
17
|
+
post_id: post.id
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def record_exists?
|
25
|
+
self.class.klass.where(attributes).exists?
|
26
|
+
end
|
27
|
+
|
28
|
+
def record_slug
|
29
|
+
return "[tag:#{record.tag_id} <-> post:#{record.post_id}]"
|
30
|
+
end
|
31
|
+
|
32
|
+
def attributes_for_create
|
33
|
+
attributes
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "ghost/seeder/models/generic_seed"
|
2
|
+
|
3
|
+
module Ghost
|
4
|
+
module Seeder
|
5
|
+
module Models
|
6
|
+
class PostsSeed < GenericSeed
|
7
|
+
def self.klass
|
8
|
+
Post
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def attributes_for_create
|
14
|
+
html = "<p>#{record.markdown.split("\n").join("</p><p>")}</p>"
|
15
|
+
attributes.merge(
|
16
|
+
author_id: first_user.id,
|
17
|
+
created_by: first_user.id,
|
18
|
+
updated_by: first_user.id,
|
19
|
+
published_by: first_user.id,
|
20
|
+
html: html
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "ghost/seeder/models/generic_seed"
|
2
|
+
|
3
|
+
module Ghost
|
4
|
+
module Seeder
|
5
|
+
module Models
|
6
|
+
class SettingsSeed < GenericSeed
|
7
|
+
DEFAULT_NAVIGATION = [
|
8
|
+
{ url: '/', label: 'Inicio' },
|
9
|
+
{ url: '/coworking/', label: 'Coworking' },
|
10
|
+
{ url: '/emprendimientos/', label: 'Emprendimientos' },
|
11
|
+
{ url: '/tag/blog/', label: 'Blog' },
|
12
|
+
]
|
13
|
+
DEFAULT_SETTINGS = [
|
14
|
+
{ key: "activeTheme", value: "prendho" },
|
15
|
+
{ key: "labs", value: '{"publicAPI":true}' },
|
16
|
+
{ key: "logo", value: '/default/prendho_logo_header.svg' },
|
17
|
+
{ key: "navigation", value: DEFAULT_NAVIGATION.to_json }
|
18
|
+
]
|
19
|
+
|
20
|
+
def self.seeds
|
21
|
+
DEFAULT_SETTINGS
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.wipe_records!
|
25
|
+
Logger.info "can't wipe", self
|
26
|
+
end
|
27
|
+
|
28
|
+
def seed!
|
29
|
+
setting.update!(value: record.value)
|
30
|
+
Logger.success self.class, "#{record.key}:", record.value
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def setting
|
36
|
+
Setting.find_by!(key: record.key)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "ghost/seeder/models/generic_seed"
|
2
|
+
|
3
|
+
module Ghost
|
4
|
+
module Seeder
|
5
|
+
module Models
|
6
|
+
class TagsSeed < GenericSeed
|
7
|
+
def self.klass
|
8
|
+
Tag
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def attributes_for_create
|
14
|
+
attributes.merge(
|
15
|
+
created_by: first_user.id,
|
16
|
+
updated_by: first_user.id
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# https://github.com/noggalito/fedes/commit/0225989bac3976fb4fea554b1c19a581aa0a74e2
|
2
|
+
require 'active_record/connection_adapters/sqlite3_adapter'
|
3
|
+
|
4
|
+
module ActiveRecord
|
5
|
+
module ConnectionAdapters
|
6
|
+
class SQLite3Adapter < AbstractAdapter
|
7
|
+
def quoted_true; '1' end
|
8
|
+
def unquoted_true; '1' end
|
9
|
+
def quoted_false; '0' end
|
10
|
+
def unquoted_false; '0' end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "ghost/seeder/logger"
|
2
|
+
require "ghost/seeder/ar_models"
|
3
|
+
require "ghost/seeder/db_connection"
|
4
|
+
require "ghost/seeder/models/tags_seed"
|
5
|
+
require "ghost/seeder/models/posts_seed"
|
6
|
+
require "ghost/seeder/models/settings_seed"
|
7
|
+
require "ghost/seeder/models/post_tags_seed"
|
8
|
+
|
9
|
+
module Ghost
|
10
|
+
module Seeder
|
11
|
+
class Runner
|
12
|
+
class << self
|
13
|
+
def run
|
14
|
+
new(environment).run
|
15
|
+
end
|
16
|
+
|
17
|
+
def environment
|
18
|
+
ENV["NODE_ENV"] || "development"
|
19
|
+
end
|
20
|
+
|
21
|
+
def wipe_db?
|
22
|
+
ENV["WIPE_DB"]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_reader :environment
|
27
|
+
|
28
|
+
def initialize(environment)
|
29
|
+
@environment = environment
|
30
|
+
end
|
31
|
+
|
32
|
+
def run
|
33
|
+
db.connect!
|
34
|
+
Logger.warn "seeding database for", environment
|
35
|
+
klasses.each do |klass|
|
36
|
+
klass.wipe_records! if self.class.wipe_db?
|
37
|
+
klass.perform_queries
|
38
|
+
Logger.success klass
|
39
|
+
end
|
40
|
+
db.disconnect!
|
41
|
+
Logger.success "finished seeding!"
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def db
|
47
|
+
@db ||= DbConnection.new(environment)
|
48
|
+
end
|
49
|
+
|
50
|
+
def klasses
|
51
|
+
[
|
52
|
+
Models::TagsSeed,
|
53
|
+
Models::PostsSeed,
|
54
|
+
Models::SettingsSeed,
|
55
|
+
Models::PostTagsSeed
|
56
|
+
]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "ghost/seeder/runner"
|
2
|
+
|
3
|
+
module Ghost
|
4
|
+
module Seeder
|
5
|
+
module Tasks
|
6
|
+
class Db
|
7
|
+
include Rake::DSL if defined? Rake::DSL
|
8
|
+
|
9
|
+
def load_tasks
|
10
|
+
namespace :db do
|
11
|
+
desc "set WIPE_DB if you want to wipe"
|
12
|
+
task :seed do
|
13
|
+
Ghost::Seeder::Runner.run
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Ghost::Seeder::Tasks::Db.new.load_tasks
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ghost-seeder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mario Andrés Correa
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '11.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '11.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faker
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colorize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.8'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.13'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.13'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- a@macool.me
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CODE_OF_CONDUCT.md
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- ghost-seeder.gemspec
|
115
|
+
- lib/ghost/seeder.rb
|
116
|
+
- lib/ghost/seeder/ar_models.rb
|
117
|
+
- lib/ghost/seeder/db_connection.rb
|
118
|
+
- lib/ghost/seeder/logger.rb
|
119
|
+
- lib/ghost/seeder/models/generic_seed.rb
|
120
|
+
- lib/ghost/seeder/models/generic_seed/yaml_bindings.rb
|
121
|
+
- lib/ghost/seeder/models/post_tags_seed.rb
|
122
|
+
- lib/ghost/seeder/models/posts_seed.rb
|
123
|
+
- lib/ghost/seeder/models/settings_seed.rb
|
124
|
+
- lib/ghost/seeder/models/tags_seed.rb
|
125
|
+
- lib/ghost/seeder/monkey_patch_sqlite3.rb
|
126
|
+
- lib/ghost/seeder/runner.rb
|
127
|
+
- lib/ghost/seeder/tasks/db.rb
|
128
|
+
- lib/ghost/seeder/version.rb
|
129
|
+
homepage: https://github.com/noggalito/ghost-seeder
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata:
|
133
|
+
allowed_push_host: https://rubygems.org
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.5.1
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Seeding ghost's DB
|
154
|
+
test_files: []
|
155
|
+
has_rdoc:
|