seedster 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +13 -0
- data/README.md +160 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/seedster/data_dumper.rb +65 -0
- data/lib/seedster/data_loader.rb +72 -0
- data/lib/seedster/file_manager.rb +49 -0
- data/lib/seedster/railtie.rb +22 -0
- data/lib/seedster/tasks/seedster.rb +44 -0
- data/lib/seedster/version.rb +18 -0
- data/lib/seedster.rb +53 -0
- data/seedster.gemspec +25 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 468b8c6fc14489ca306402904281050c991ab991
|
4
|
+
data.tar.gz: 59cf2ae2eb89467266ad9d9d507318b4cf9f6604
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89ae08729c0184f4a8cd7ce1096b2a2148763fb7e2125f12824756c6cec3f9af0107369a6d80855a0e380ec40b2313f581acb5c766192e0cffa05f96d69ae7cb
|
7
|
+
data.tar.gz: 60fe5fc13cc95c498acef17d47ac08f193267f926a01830b28690afbe6e57f79dc0ac18206bcda2bb2124f16e8ec119b788ca046aa05542bff5eb180ba910b9d
|
data/.gitignore
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 opensource@groupon.com. 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/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
seedster (0.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.11.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.16)
|
17
|
+
minitest (~> 5.0)
|
18
|
+
rake (~> 10.0)
|
19
|
+
seedster!
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2019 Groupon, Inc.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# Seedster
|
2
|
+
|
3
|
+
Seedster is a way to work with real content in a development database, for a Rails application that uses Postgres.
|
4
|
+
|
5
|
+
> Why not use the built-in Rails seed mechanism?
|
6
|
+
|
7
|
+
We preferred a custom solution so that the development data was based on real production data, with referential integrity intact. What we settled on was exporting particular rows of data all driven from a specific user, to provide a meaningful set of related data that could periodically be refreshed with minimal effort over time.
|
8
|
+
|
9
|
+
> Briefly, how is it different from Rails' db seeds?
|
10
|
+
|
11
|
+
With Seedster, you write SQL queries for the tables you want data from. The queries can have a parameter like a user ID. A Rake task is provided to dump data from a production database, and a separate task is provided to load data locally on developers machines.
|
12
|
+
|
13
|
+
> This works with real user data?
|
14
|
+
|
15
|
+
Seedster uses content from a real user, so the recommendation is to use an employee user, test user, or something along those lines, so that the content being used for development is appropriate to share on a development team. Dump files can be viewed by all team members, to ensure they are based on an agreed upon user's data.
|
16
|
+
|
17
|
+
> What are the dependencies?
|
18
|
+
|
19
|
+
Seedster has developed for use with a Postgres database and depends on `psql`, `ssh`, `scp`, and `tar`.
|
20
|
+
|
21
|
+
|
22
|
+
## Process Overview
|
23
|
+
|
24
|
+
Requirements and expectations:
|
25
|
+
|
26
|
+
* Local and remote database schema versions are in same. The development database is empty prior to load.
|
27
|
+
* Use the provided Rake task to dump data from production. `rake seedster:dump` Individual dump files are consolidated into a single tar file.
|
28
|
+
* Use the provided Rake task to download data file (`rake seedster:load`) to download, extract, and load the data
|
29
|
+
* Use ENV variables to pass in dynamic data to SQL queries responsible for selecting data, for example supply `USER_ID` with a value on the command line, and add a parameter to your SQL query with syntax like this `%{}`, for example: `SELECT * FROM users WHERE id = '%{user_id}'`.
|
30
|
+
|
31
|
+
|
32
|
+
In order to dump the data for user ID 1, using a parameterized SQL query that expects a value for `user_id`:
|
33
|
+
|
34
|
+
```
|
35
|
+
prod_shell> USER_ID=1 rake seedster:dump
|
36
|
+
```
|
37
|
+
|
38
|
+
To download, extract, and load the data file:
|
39
|
+
|
40
|
+
```
|
41
|
+
dev_shell> rake seedster:load
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
## Installation
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
gem 'seedster'
|
49
|
+
```
|
50
|
+
|
51
|
+
And then execute:
|
52
|
+
|
53
|
+
$ bundle
|
54
|
+
|
55
|
+
Or install it yourself as:
|
56
|
+
|
57
|
+
$ gem install seedster
|
58
|
+
|
59
|
+
## Initializer
|
60
|
+
|
61
|
+
An initializer is required to make Seedster work with your hosts, database, ssh config, and really drives everything that is unique to your application.
|
62
|
+
|
63
|
+
Create a file `config/initializers/seedster.rb` with content like this:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
Seedster.configure do |c|
|
67
|
+
c.db_host = 'XXX'
|
68
|
+
c.db_name = 'XXX'
|
69
|
+
c.db_username = 'XXX'
|
70
|
+
c.db_password = 'XXX'
|
71
|
+
c.remote_host_path = '/var/company/www/app/current'
|
72
|
+
c.query_params = {user_id: XXX}
|
73
|
+
c.ssh_user = 'XXX'
|
74
|
+
c.dump_host = 'XXX'
|
75
|
+
c.tables = [
|
76
|
+
{
|
77
|
+
query: %{SELECT * FROM users WHERE id = '%{user_id}'},
|
78
|
+
name: 'users'
|
79
|
+
},
|
80
|
+
{
|
81
|
+
/* more tables here */
|
82
|
+
}
|
83
|
+
]
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
|
88
|
+
### Initializer config options
|
89
|
+
|
90
|
+
##### `db_host`
|
91
|
+
|
92
|
+
Production database host. We use a read-only replica
|
93
|
+
|
94
|
+
##### `db_name`
|
95
|
+
|
96
|
+
Production database name
|
97
|
+
|
98
|
+
##### `db_username`
|
99
|
+
|
100
|
+
Production database username
|
101
|
+
|
102
|
+
##### `db_password`
|
103
|
+
|
104
|
+
Production database password
|
105
|
+
|
106
|
+
##### `remote_host_path`
|
107
|
+
|
108
|
+
The path on the production host where the application is deployed. For example: `/var/company/www/app/current`.
|
109
|
+
|
110
|
+
##### `query_params`
|
111
|
+
|
112
|
+
To use a parameter like `user_id` in SQL queries, passing the value in via an environment variable like `USER_ID=1`, provide a mapping like this `{user_id: ENV['user_id']}`. Provide any additional key and value mappings you expect to be present when the query executes.
|
113
|
+
|
114
|
+
##### `ssh_user`
|
115
|
+
|
116
|
+
An SSH user that can connect (for purposes of downloading the file with `scp`) to the host where the production dump is.
|
117
|
+
|
118
|
+
##### `dump_host`
|
119
|
+
|
120
|
+
The host (a hostname) where the dump file is stored. We made this configurable to be able to dump data from production and staging.
|
121
|
+
|
122
|
+
##### `tables`
|
123
|
+
|
124
|
+
e.g. `tables = [ /* {name: '', query: '' } */ ]`
|
125
|
+
|
126
|
+
The tables option is where each query is stored. This is currently an array of hashes, with two items, `name` and `query`. `name` is the name of the database table, and `query` is the SQL query. We are dumping 10-15 tables worth of data for the same user, so that means we have 10-15 items specified here. This is where we would modify those queries over time to include or exclude more tables or fields of data.
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
## Development
|
131
|
+
|
132
|
+
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).
|
133
|
+
|
134
|
+
## Testing
|
135
|
+
|
136
|
+
Run the test suite with `rake test`.
|
137
|
+
|
138
|
+
## Contributing
|
139
|
+
|
140
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/groupon/seedster. 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.
|
141
|
+
|
142
|
+
## Releasing a new version
|
143
|
+
|
144
|
+
1. Update the version in `seedster.gemspec`
|
145
|
+
2. `git commit seedster.gemspec` with the following message format:
|
146
|
+
|
147
|
+
Version x.x.x
|
148
|
+
|
149
|
+
Changelog:
|
150
|
+
* Some new feature
|
151
|
+
* Some new bug fix
|
152
|
+
3. `rake release`
|
153
|
+
|
154
|
+
## License
|
155
|
+
|
156
|
+
The gem is available as open source under the terms of the [APACHE LICENSE, VERSION 2.0](https://www.apache.org/licenses/LICENSE-2.0).
|
157
|
+
|
158
|
+
## Code of Conduct
|
159
|
+
|
160
|
+
Everyone interacting in the Seedster project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/groupon/seedster/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "seedster"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2019 Groupon, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module Seedster
|
17
|
+
class DataDumper
|
18
|
+
attr_accessor :db_password
|
19
|
+
attr_reader :db_host, :db_username, :db_name
|
20
|
+
|
21
|
+
def initialize(db_password:, db_host:, db_username:, db_name:)
|
22
|
+
@db_password = db_password
|
23
|
+
@db_host = db_host
|
24
|
+
@db_username = db_username
|
25
|
+
@db_name = db_name
|
26
|
+
FileManager.create_seed_file_dir
|
27
|
+
end
|
28
|
+
|
29
|
+
def dump!
|
30
|
+
dump_tables
|
31
|
+
create_consolidated_dump_file
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# Configuration parameters passed in via a hash here should be substituted into the query
|
37
|
+
# Within the query, indicate a parameter to be replaced by using syntax like:
|
38
|
+
#
|
39
|
+
# %{user_id}
|
40
|
+
#
|
41
|
+
def dump_tables
|
42
|
+
Seedster.configuration.tables.each do |item|
|
43
|
+
full_query = item[:query] % Seedster.configuration.query_params
|
44
|
+
sql_results_to_file(
|
45
|
+
sql: full_query,
|
46
|
+
table_name: item[:name]
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_consolidated_dump_file
|
52
|
+
dump_file = Rails.root.join(FileManager.dump_dir, FileManager.dump_file_name)
|
53
|
+
puts "Creating dump file '#{dump_file}' from '#{FileManager.seed_file_dir}'"
|
54
|
+
tar_command = "tar -zcvf #{dump_file} -C #{FileManager.seed_file_dir} ." # use relative paths
|
55
|
+
system(tar_command) # use relative paths
|
56
|
+
end
|
57
|
+
|
58
|
+
def sql_results_to_file(sql:, table_name:)
|
59
|
+
filename = FileManager.get_filename(table_name: table_name)
|
60
|
+
puts "dumping '#{table_name}' to '#{filename}' with query '#{sql}'"
|
61
|
+
psql_cmd = %{PGPASSWORD=#{db_password} psql -h #{db_host} -d #{db_name} -U #{db_username} -c "\\copy (#{sql}) TO '#{filename}' WITH CSV"}
|
62
|
+
system(psql_cmd)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2019 Groupon, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module Seedster
|
17
|
+
class DataLoader
|
18
|
+
attr_reader :ssh_user, :ssh_host, :local_db_name,
|
19
|
+
:remote_host_path
|
20
|
+
|
21
|
+
def initialize(ssh_user:, ssh_host:,
|
22
|
+
local_db_name:, remote_host_path:)
|
23
|
+
@ssh_user = ssh_user
|
24
|
+
@ssh_host = ssh_host
|
25
|
+
@local_db_name = local_db_name
|
26
|
+
@remote_host_path = remote_host_path
|
27
|
+
print_greeting
|
28
|
+
FileManager.create_seed_file_dir
|
29
|
+
end
|
30
|
+
|
31
|
+
def load!
|
32
|
+
download_and_extract_file
|
33
|
+
|
34
|
+
Seedster.configuration.tables.each do |item|
|
35
|
+
load_data(table_name: item[:name])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def download_and_extract_file
|
42
|
+
remote_host_path = Seedster.configuration.remote_host_path
|
43
|
+
remote_file = "#{remote_host_path}/#{File.join(FileManager.dump_dir, FileManager.dump_file_name)}"
|
44
|
+
scp_command = "scp -r #{ssh_user}@#{ssh_host}:#{remote_file} ."
|
45
|
+
puts "Downloading file: #{scp_command}"
|
46
|
+
system(scp_command)
|
47
|
+
|
48
|
+
untar_command = "tar -zxvf #{FileManager.dump_file_name} -C #{FileManager.seed_file_dir}"
|
49
|
+
puts "Extracting local file: #{untar_command}"
|
50
|
+
system(untar_command)
|
51
|
+
end
|
52
|
+
|
53
|
+
def load_data(table_name:)
|
54
|
+
filename = FileManager.get_filename(table_name: table_name)
|
55
|
+
load_command = "COPY #{table_name} FROM '#{filename}' DELIMITERS ',' CSV"
|
56
|
+
puts "loading '#{table_name}' from '#{filename}'"
|
57
|
+
psql_cmd = %{psql -d '#{local_db_name}' -c "#{load_command}"}
|
58
|
+
system(psql_cmd)
|
59
|
+
end
|
60
|
+
|
61
|
+
def print_greeting
|
62
|
+
puts
|
63
|
+
puts "🌱🌱🌱🌱🌱"
|
64
|
+
puts "Hello from Seedster!"
|
65
|
+
puts
|
66
|
+
puts "Loading data requires a compatible schema version, and empty tables."
|
67
|
+
puts "Before loading data locally, truncate the relevant tables (or you may see constraint errors)."
|
68
|
+
puts "🌱🌱🌱🌱🌱"
|
69
|
+
puts
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2019 Groupon, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module Seedster
|
17
|
+
class FileManager
|
18
|
+
SEEDSTER = 'seedster'
|
19
|
+
TMP_DIR = 'tmp'
|
20
|
+
DATA_DUMPS_DIR = 'data_dumps'
|
21
|
+
SEED_FILE_DIR = 'seedster_data_dumps'
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def dump_dir
|
25
|
+
# Capistrano note:
|
26
|
+
# set up as a linked_dir in config/deploy.rb
|
27
|
+
File.join(TMP_DIR, DATA_DUMPS_DIR)
|
28
|
+
end
|
29
|
+
|
30
|
+
# TODO: mock Rails.root here for test
|
31
|
+
def seed_file_dir
|
32
|
+
Rails.root.join(TMP_DIR, SEED_FILE_DIR)
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_filename(table_name:)
|
36
|
+
File.join(seed_file_dir, "#{SEEDSTER}-#{table_name}.csv")
|
37
|
+
end
|
38
|
+
|
39
|
+
def dump_file_name
|
40
|
+
"#{SEEDSTER}-dump-latest.tar.gz"
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_seed_file_dir
|
44
|
+
puts "Setting up '#{FileManager.seed_file_dir}' directory"
|
45
|
+
FileUtils.mkdir_p(seed_file_dir)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2019 Groupon, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module Seedster
|
17
|
+
class Railtie < Rails::Railtie
|
18
|
+
rake_tasks do
|
19
|
+
require 'seedster/tasks/seedster'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2019 Groupon, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
require 'seedster'
|
17
|
+
|
18
|
+
namespace :seedster do
|
19
|
+
desc "Dump application seed data to a data dump file"
|
20
|
+
task dump: :environment do
|
21
|
+
puts "Seedster loading..."
|
22
|
+
|
23
|
+
Seedster::DataDumper.new(
|
24
|
+
db_host: Seedster.configuration.db_host,
|
25
|
+
db_name: Seedster.configuration.db_name,
|
26
|
+
db_username: Seedster.configuration.db_username,
|
27
|
+
db_password: Seedster.configuration.db_password
|
28
|
+
).dump!
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "Load application seed data from a remote dump file"
|
32
|
+
task load: :environment do
|
33
|
+
return unless Rails.env.development? # only load in dev environment
|
34
|
+
|
35
|
+
config = Rails.configuration.database_configuration
|
36
|
+
Seedster::DataLoader.new(
|
37
|
+
local_db_name: config['development']['database'],
|
38
|
+
ssh_user: Seedster.configuration.ssh_user,
|
39
|
+
ssh_host: Seedster.configuration.dump_host,
|
40
|
+
remote_host_path: Seedster.configuration.remote_host_path
|
41
|
+
).load!
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2019 Groupon, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module Seedster
|
17
|
+
VERSION = '0.1.4'
|
18
|
+
end
|
data/lib/seedster.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2019 Groupon, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
require 'seedster/version'
|
17
|
+
require 'seedster/railtie' if defined?(Rails)
|
18
|
+
require 'seedster/file_manager'
|
19
|
+
require 'seedster/data_dumper'
|
20
|
+
require 'seedster/data_loader'
|
21
|
+
|
22
|
+
module Seedster
|
23
|
+
class << self
|
24
|
+
attr_accessor :configuration
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.configure
|
28
|
+
self.configuration ||= Configuration.new
|
29
|
+
yield(configuration)
|
30
|
+
end
|
31
|
+
|
32
|
+
class Configuration
|
33
|
+
attr_accessor :db_host, :db_name,
|
34
|
+
:db_username, :db_password,
|
35
|
+
:remote_host_path,
|
36
|
+
:query_params,
|
37
|
+
:ssh_user,
|
38
|
+
:dump_host,
|
39
|
+
:tables
|
40
|
+
|
41
|
+
def initialize
|
42
|
+
@db_host = nil
|
43
|
+
@db_name = nil
|
44
|
+
@db_username = nil
|
45
|
+
@db_password = nil
|
46
|
+
@remote_host_path = nil
|
47
|
+
@query_params = {}
|
48
|
+
@ssh_user = nil
|
49
|
+
@dump_host = nil
|
50
|
+
@tables = []
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/seedster.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "seedster/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "seedster"
|
7
|
+
spec.version = Seedster::VERSION
|
8
|
+
spec.authors = ["Groupon"]
|
9
|
+
spec.email = ["opensource@groupon.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Work with real content in development}
|
12
|
+
spec.description = %q{Easily load real application content for local development}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "Apache2"
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
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.16"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: seedster
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Groupon
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: Easily load real application content for local development
|
56
|
+
email:
|
57
|
+
- opensource@groupon.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- CODE_OF_CONDUCT.md
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/seedster.rb
|
73
|
+
- lib/seedster/data_dumper.rb
|
74
|
+
- lib/seedster/data_loader.rb
|
75
|
+
- lib/seedster/file_manager.rb
|
76
|
+
- lib/seedster/railtie.rb
|
77
|
+
- lib/seedster/tasks/seedster.rb
|
78
|
+
- lib/seedster/version.rb
|
79
|
+
- seedster.gemspec
|
80
|
+
homepage: ''
|
81
|
+
licenses:
|
82
|
+
- Apache2
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.6.11
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Work with real content in development
|
104
|
+
test_files: []
|