prodder 1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3d5918237e7d482b189ba2649512fcd4d94254e3
4
+ data.tar.gz: d717694eea4567462ce9e2b83ee0b3d4e165a085
5
+ SHA512:
6
+ metadata.gz: 389fc841cfcfc4edb3d1605d947f391a61bd069d0f3b36957b61b9a9e53f6671580206d6827307758d43068b6ecc455c3ed672a828455803d29dc7fd5b91fd03
7
+ data.tar.gz: 2e521a6654a9092c5eff82ef840322e837e8f4379c3d2faf7ecaa8cd4061d679c52a0817b41b719e7af048f130f3d5edcd1a3f5141a1195beddaddeb37eba9dd
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+
20
+ nc.yml
21
+ prodder-workspace/
22
+ features/support/blog.git
@@ -0,0 +1,52 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ rvm:
5
+ - 2.3.0
6
+ - 2.2.4
7
+ - 2.1.8
8
+
9
+ env:
10
+ matrix:
11
+ - PG_VERSION=9.3
12
+ - PG_VERSION=9.4
13
+ - PG_VERSION=9.5
14
+
15
+ before_install:
16
+ - git config --global user.name "Prodder In Travis-CI"
17
+ - git config --global user.email "prodder@example.com"
18
+ # install postgresql v9.5
19
+ - if [[ "$PG_VERSION" = "9.5" ]]; then echo "installing pg9.5"; sudo /etc/init.d/postgresql stop; sudo apt-get -y autoremove; sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 7FCC7D46ACCC4CF8; sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main 9.5" >> /etc/apt/sources.list.d/postgresql.list'; sudo apt-get update; sudo apt-get -y install postgresql-9.5; sudo cp /etc/postgresql/9.4/main/pg_hba.conf /etc/postgresql/9.5/main/pg_hba.conf; sudo sed -i 's/5433/5432/' /etc/postgresql/9.5/main/postgresql.conf; sudo /etc/init.d/postgresql restart; else echo "not installing pg9.5"; fi
20
+ # setup travis user
21
+ - if [[ "$PG_VERSION" = "9.5" ]]; then echo "setting up users for pg9.5"; PGUSER=postgres createuser --superuser travis; fi
22
+ # setup pg_dump
23
+ - sudo ln -sfn /usr/lib/postgresql/$PG_VERSION/bin/pg_dump /usr/bin/pg_dump
24
+ # start up the specific version of PG
25
+ - sudo -E sh -c 'service postgresql stop'
26
+ - sleep 5s
27
+ - sudo -E sh -c 'service postgresql start $PG_VERSION'
28
+ - psql -U postgres -d postgres -c 'select setting from pg_settings where name = $m$server_version$m$;'
29
+
30
+ script:
31
+ - echo "===================================================="
32
+ - echo "PG_VERSION|$PG_VERSION|"
33
+ - echo "===================================================="
34
+ - psql --version
35
+ - echo "===================================================="
36
+ - pg_lsclusters
37
+ - echo "===================================================="
38
+ - psql -U postgres -d postgres -c 'select 1;'
39
+ - echo "===================================================="
40
+ - ls -al `which pg_dump`
41
+ - echo "===================================================="
42
+ - bundle exec rake spec
43
+ - bundle exec rake cucumber
44
+
45
+ deploy:
46
+ provider: rubygems
47
+ api_key:
48
+ secure: "UhUkPFhEuI1dLPa4skTUdOBcGY2SEkRP3N9jLDQad04DflV+GutcjrfN1iQxWk59gVt3zqird5FS8SdwCFuOn8DAU9ACtg73xiPPWRRTdzma4Qw+4thuOHcdwPBz3762YFTRyH7IbRTAlxaD6qPz6US3BnYAkJU7C8c30rHLX6cZutjLV4FsvWonkzxcjyEUViVEdBM0kzI+tdBnQovpcM67a9AfxxBZITJLIfIcah1qc/RANpLkUFJCwNyH9oARWsGIvpIKcQEJBhsl04tvbNRLpiMCk1e1RS1bjMdbbx/rVm3C7dvAjUznbr3ON9abgoe6QDDYr6kXPJbylmxFUzA7ftBWjz2nNruRncsohx08LaM4ADRJWKB3XbP5BXkwUgE672Fi20+Z78LwWfjrr3iRVm7u9Mt9pZHG6Ih8Jy64Uq3647kdVZu9APPfn1NZETFG7vLAMZUtPXv7HBkujlq23XdYXax1XYYbYsM0LOlnG6ol2y6OrBrxWIqC+E8UmLXf/+/MS4j3v2RAe7jXh6fFlw+5MjLr3HXqZ12CrAChp22NRPp1OY4Hac4zzRwGeVOgewknpOK7qQfVFFaQoQksU6VaenSx+TxcYOZYuQdrQjfbO6c+Q/vvZ1RoPOEwH0AelkrW2eGqQTNVWIbH5vvfhys68SA8ov8gNnIzMtU="
49
+ gem: prodder
50
+ on:
51
+ tags: true
52
+ repo: enova/prodder
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'deject'
4
+ gem 'thor'
5
+ gem 'cocaine'
6
+ gem 'benzo'
7
+
8
+ group :development, :test do
9
+ gem 'rake'
10
+ gem 'pry'
11
+ gem 'pry-remote'
12
+ gem 'rspec'
13
+ gem 'cucumber'
14
+ gem 'aruba'
15
+ gem 'pg'
16
+ end
@@ -0,0 +1,64 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ aruba (0.5.1)
5
+ childprocess (~> 0.3.6)
6
+ cucumber (>= 1.1.1)
7
+ rspec-expectations (>= 2.7.0)
8
+ benzo (2.0.0)
9
+ cocaine (~> 0.4.2)
10
+ builder (3.1.4)
11
+ childprocess (0.3.6)
12
+ ffi (~> 1.0, >= 1.0.6)
13
+ cocaine (0.4.2)
14
+ coderay (1.0.8)
15
+ cucumber (1.2.1)
16
+ builder (>= 2.1.2)
17
+ diff-lcs (>= 1.1.3)
18
+ gherkin (~> 2.11.0)
19
+ json (>= 1.4.6)
20
+ deject (0.2.3)
21
+ diff-lcs (1.1.3)
22
+ ffi (1.2.0)
23
+ gherkin (2.11.5)
24
+ json (>= 1.4.6)
25
+ json (1.8.3)
26
+ method_source (0.8.1)
27
+ pg (0.18.2)
28
+ pry (0.9.10)
29
+ coderay (~> 1.0.5)
30
+ method_source (~> 0.8)
31
+ slop (~> 3.3.1)
32
+ pry-remote (0.1.6)
33
+ pry (~> 0.9)
34
+ slop (~> 3.0)
35
+ rake (10.0.3)
36
+ rspec (2.12.0)
37
+ rspec-core (~> 2.12.0)
38
+ rspec-expectations (~> 2.12.0)
39
+ rspec-mocks (~> 2.12.0)
40
+ rspec-core (2.12.2)
41
+ rspec-expectations (2.12.1)
42
+ diff-lcs (~> 1.1.3)
43
+ rspec-mocks (2.12.1)
44
+ slop (3.3.3)
45
+ thor (0.16.0)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ aruba
52
+ benzo
53
+ cocaine
54
+ cucumber
55
+ deject
56
+ pg
57
+ pry
58
+ pry-remote
59
+ rake
60
+ rspec
61
+ thor
62
+
63
+ BUNDLED WITH
64
+ 1.11.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Enova
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.
@@ -0,0 +1,272 @@
1
+
2
+ prodder [![Build Status](https://travis-ci.org/enova/prodder.svg?branch=master)](https://travis-ci.org/enova/prodder)
3
+ =======
4
+
5
+ A tool to maintain and load your Rails application's database structure and seed
6
+ table contents, based on its migration history and the current in production
7
+ databases.
8
+
9
+ In short: `db:reset db:migrate`
10
+
11
+ 1. Your project maintains `db/structure.sql`, `db/seeds.sql`, and optional
12
+ `db/quality_checks.sql` and `db/permissions.sql` files as it sees fit (ie, by using `prodder` as a script to dump
13
+ production and push it to your git repository).
14
+ 2. Make sure `db/seeds.sql` includes the `schema_migrations` table.
15
+ 3. Only new migrations will be run against prod's structure using its seed table contents.
16
+ 4. Once a migration has been deployed, it should result in `db/structure.sql` and
17
+ `db/quality_checks.sql` files being modified, and any new seed data being added to
18
+ `db/seeds.sql` -- including the new entry in `schema_migrations`.
19
+ 5. That migration never needs to be run in development again. Feel free to `rm`.
20
+ 6. Any application related permission changes will result in `db/permissions.sql` being modified.
21
+
22
+ ## Replacing `rake db:*`
23
+ `prodder` can be included as a railtie in your application to automatically
24
+ replace many of Rails' `db:*` tasks. The only prerequisites to its usage are
25
+ the existence of `db/structure.sql`, `db/seeds.sql` with at least the
26
+ `schema_migrations` table contents included. Optional `db/quality_checks.sql` and `db/permissions.sql`
27
+ will be loaded after seeding, which can be helpful if you wish to seed the database
28
+ prior to enforcing foreign key constraints and if you want to develop in an environment
29
+ with the same permissions setup as production.
30
+
31
+ ### Installation
32
+ In your Gemfile:
33
+
34
+ ```ruby
35
+ gem 'prodder', require: 'prodder/railtie'
36
+ ```
37
+
38
+ It doesn't really matter, but for sanity's sake, you should set your `schema_format`
39
+ to `:sql`:
40
+
41
+ ```ruby
42
+ # config/application.rb
43
+ module Whatever
44
+ class Application
45
+ config.active_record.schema_format = :sql
46
+ end
47
+ end
48
+ ```
49
+
50
+ If you want to work with permissions setup like production:
51
+ ```ruby
52
+ # config/database.yml
53
+
54
+ username: user_who_will_run_your_app (# for example identity__web)
55
+ migration_user: migration_overlay_user_who_is_usually_db_owner (# for example identity__owner)
56
+ superuser: godmode (# for example postgres)
57
+ ```
58
+
59
+ Note that the `migration_user` and `superuser` must be created before you run `db:reset db:migrate`, just as you would have to when you have to
60
+ create the `username: user` even with the standard setup. Note that this is only ever recommended for development environments. Do NOT
61
+ mess with production overlays to have 3 different users in production, that's the reason for having overlays in the first place.You can also
62
+ easily control this by making the gem a `group :development` only dependency:
63
+
64
+ ```
65
+ #!/usr/bin/env bash
66
+
67
+ set -eu
68
+
69
+ createuser --superuser --createrole --createdb godmode || true
70
+ createuser --createrole migration_overlay_user_who_is_usually_db_owner || true
71
+
72
+ bundle install
73
+ bundle exec rake db:reset db:migrate
74
+ ```
75
+
76
+ ### Usage
77
+ Things that really matter:
78
+
79
+ 1. `rake db:reset` recreates your database, loading `db/structure.sql`, `db/seeds.sql`,
80
+ `db/quality_checks.sql` and `permissions.sql`.
81
+ 2. `rake db:migrate` runs migrations, as before, but runs *after* the initial seeds were
82
+ created. Those initial seeds should have included your production app's `schema_migrations`
83
+ table contents. This means only those migrations that have not yet run in production
84
+ will need to be run locally.
85
+ 3. If you configred to have 3 users in your `#config/database.yml` file and have a `permissions.sql` file present,
86
+ all your `db:*` commands will be run in the context of the user it makes the most sense to run as, mimicking
87
+ our production environment. For instance(s), to reset the database (god forbid we do this in production), it will
88
+ run as `superuser`, to run a migration, as the `migration_user` and your application will connect to the database
89
+ as `username`. Thus it achieves the overlays of a DBA, migration and production application.
90
+ 4. Having 3 users configured and to achieve the effects of step 3, you must have a `permissions.sql`. However, you do
91
+ not need to have 3 users configured to restore permissions (load the `permissions.sql` file). This being said, it
92
+ does not make sense to restore permissions in your environment if you're just going to run everything as a single,
93
+ most likely superuser.
94
+
95
+
96
+ ### Details
97
+
98
+ This will remove the `db:*` tasks:
99
+
100
+ * `db:_dump`: an internal task used by rails to dump the schema after migrations. Obsolete.
101
+ * `db:drop:*`
102
+ * `db:create:*`
103
+ * `db:migrate`
104
+ * `db:migrate:reset`
105
+ * `db:migrate:up`
106
+ * `db:migrate:down`
107
+ * `db:fixtures:.*`
108
+ * `db:abort_if_pending_migrations`
109
+ * `db:purge:*`
110
+ * `db:charset`
111
+ * `db:collation`
112
+ * `db:rollback`
113
+ * `db:version`
114
+ * `db:forward`
115
+ * `db:reset`
116
+ * `db:schema:*`
117
+ * `db:seed`
118
+ * `db:setup`
119
+ * `db:structure:*`
120
+ * `db:test:*`
121
+ * `test:prepare`: Rails 4.1 added this task to auto-maintain the test DB schema.
122
+
123
+ And reimplement only the following:
124
+
125
+ * `db:structure:load`: Load the contents of `db/structure.sql` into the database of your current environment.
126
+ * `db:seed`: Load `db/seeds.sql` into the database of your current environment.
127
+ * `db:quality_check`: Load `db/quality_checks.sql` into the database of your current environment, if present.
128
+ * `db:reset`: db:drop db:setup
129
+ * `db:settings`: Load the contents of `db/settings.sql` into the database of your current environment.
130
+ * `db:setup`: db:create db:structure:load db:seed db:quality_check db:settings
131
+ * `db:test:prepare`: RAILS_ENV=test db:reset db:migrate
132
+ * `db:test:clone_structure`: RAILS_ENV=test db:reset db:migrate
133
+ * `test:prepare`: db:test:prepare
134
+ * `db:drop`: Drop database as superuser
135
+ * `db:create`: Create database as `superuser` and transfer ownership to `migration_user`
136
+ * `db:migrate:*`, `db:rollback` Run migrations up/down as `migration_user`
137
+ * `db:purge:*, db:charset, db:collation, db:version, db:forward, db:rollback, db:abort_if_pending_migrations` as
138
+ appropriate users.
139
+
140
+ See [lib/prodder/prodder.rake](lib/prodder/prodder.rake)
141
+ for more info.
142
+
143
+ This is likely to cause issues across Rails versions. No other choice really. It
144
+ has been used in anger on Rails 3.2.x and Rails 4.1.x.
145
+
146
+ Confirmed working versions of Postgres:
147
+
148
+ * 9.1.11+
149
+ * 9.2.6+
150
+
151
+ ## Using prodder to maintain `db/*` files
152
+
153
+ ### Example configuration
154
+
155
+ `prodder` is configured using a simplistic YAML file. There is no logic performed
156
+ to locate that file; the path to it *must* be provided each time `prodder` is
157
+ invoked.
158
+
159
+ ```yaml
160
+ # Each top-level key is the name of the Rails project for which we are updating
161
+ # the structure and seed data. Let's pretend we're maintaining a online store.
162
+
163
+ store:
164
+ structure_file: db/structure.sql
165
+ seed_file: db/seeds.sql
166
+ quality_check_file: db/quality_checks.sql
167
+ permissions:
168
+ file: db/permissions.sql
169
+ included_users: service__owner, service__web, prodder__read_only
170
+ git:
171
+ origin: git@github.com:pd/store.git
172
+ author: prodder auto-commit <pd+prodder@krh.me>
173
+ db:
174
+ name: store_production_db
175
+ host: store-db.krh.me
176
+ user: prodder_readonly
177
+ password: super-secret
178
+ tables:
179
+ - schema_migrations
180
+ - coupons
181
+ - products
182
+ - vendors
183
+ exclude_tables:
184
+ - production_only_table
185
+ exclude_schemas:
186
+ - production_only_replication_schema
187
+ ```
188
+
189
+ If you would prefer to maintain the list of seed tables within your application
190
+ itself, the `db.tables` key can be given the path to a YAML file from which to
191
+ load the list instead:
192
+
193
+ ```yaml
194
+ # prodder-config.yml
195
+ store:
196
+ # [snip]
197
+ db:
198
+ tables: config/seeds.yml
199
+
200
+ # store/config/seeds.yml:
201
+ - schema_migrations
202
+ - coupons
203
+ - products
204
+ - vendors
205
+ ```
206
+
207
+ ### Quality Checks
208
+ In some cases, such as foreign key dependencies and triggers, you may wish to defer
209
+ loading constraints on your tables until _after_ your seed data has been loaded.
210
+ `prodder` treats the presence of a `quality_check_file` key in the configuration
211
+ as an indication that it should split `structure_file` into those statements which
212
+ create the base structure, and put the constraints into the `quality_check_file`.
213
+
214
+ ### Permissions
215
+ We have had multiple cases in the past with deployments failing because some role
216
+ cannot access something on prod. To fail early and catch these in development, it
217
+ would be easier to just have these permissions loaded in development environments.
218
+ However, note that to actually take advantage of these restored permissions, you
219
+ must configure the 3 users as mentioned before in `#config/database.yml`.
220
+
221
+ ```yaml
222
+ store:
223
+ structure_file: db/structure.sql # CREATE TABLE ...
224
+ quality_check_file: db/constraints.sql # ALTER TABLE ... ADD FOREIGN KEY ...
225
+ ```
226
+
227
+
228
+ ### Example usage
229
+
230
+ The `-c` option to specify the configuration file is always required. All
231
+ options should be passed at the end of the command line.
232
+
233
+ ```
234
+ # Clone all the repositories in prodder.yml, update the remotes for
235
+ # any that already existed but have new origins specified, and
236
+ # check out the branch specified in the config. The branch must be
237
+ # the name of an available remote branch, as the local branch will
238
+ # be forcibly reset to its current SHA with `git reset --hard`.
239
+ $ prodder init -c prodder.yml
240
+
241
+ # Dump the remote databases' structures and seed tables into the
242
+ # files specified by structure_file and seed_file.
243
+ $ prodder dump -c prodder.yml
244
+
245
+ # Lots of projects? Dump just one or two:
246
+ $ prodder dump store chordgen -c prodder.yml
247
+
248
+ # Commit the changes to each project's repository. Only repositories
249
+ # with actual changes will be committed.
250
+ $ prodder commit -c prodder.yml
251
+
252
+ # Push.
253
+ $ prodder push -c prodder.yml
254
+ ```
255
+
256
+ ## TODO
257
+ * Log activity as it is performed.
258
+ * Support tracking a particular branch instead of master.
259
+ * Support specifying the options to pass to each pg_dump form.
260
+ * Select dumping only a subset of a seed table. (pg_dump won't do this ...)
261
+
262
+ ## Previous Contributors
263
+ * [Kyle Hargraves](https://github.com/pd)
264
+ * [Sri Rangarajan](https://github.com/Slania)
265
+ * [Emmanuel Sambo](https://github.com/esambo)
266
+ * [Cindy Wise](https://github.com/cyyyz)
267
+ * [Robert Nubel](https://github.com/rnubel)
268
+ * [Josh Cheek](https://github.com/JoshCheek)
269
+
270
+ ## License
271
+
272
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).