table_saw 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +11 -0
- data/Gemfile.lock +2 -2
- data/README.md +85 -7
- data/exe/table-saw +3 -2
- data/lib/table_saw/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d488fbc1065d74a9ee27d2197634b8caa66859f0658a83e268e44c9b9a8534f4
|
4
|
+
data.tar.gz: 269976846ca8d1a75282cc22228953ae798e65287f559ccb5881093311fd5252
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e275dc24ffa5107f9512c90deaf803bfcda080b277bb4f25049dc4f0ea1b84d75f7dbad9a3b5b5168871644356beec801ede7203464ea86a99d0964e7c29d790
|
7
|
+
data.tar.gz: 31f5764301e19166431bd9f9ee055f33de9f57488b4e4184e4f4a79a6d1ab962690e0cd46fb7976e948b2aded7f89eda5620ef4f9bc4c749af7782c820bff57e
|
data/.travis.yml
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
---
|
2
2
|
sudo: false
|
3
|
+
env:
|
4
|
+
global:
|
5
|
+
- CC_TEST_REPORTER_ID=5432d4e95a7749f237cf9e659c44ba28c5c91fa65436b15c5bc849d6d9ebc049
|
3
6
|
language: ruby
|
4
7
|
cache: bundler
|
5
8
|
rvm:
|
6
9
|
- 2.5.5
|
7
10
|
- 2.6.3
|
8
11
|
before_install: gem install bundler -v 2.0.1
|
12
|
+
before_script:
|
13
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
14
|
+
- chmod +x ./cc-test-reporter
|
15
|
+
- ./cc-test-reporter before-build
|
16
|
+
script:
|
17
|
+
- bundle exec rspec
|
18
|
+
after_script:
|
19
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
table_saw (0.2.
|
4
|
+
table_saw (0.2.1)
|
5
5
|
connection_pool
|
6
6
|
pg
|
7
7
|
thor
|
@@ -40,7 +40,7 @@ GEM
|
|
40
40
|
railties (>= 3.0.0)
|
41
41
|
thor (>= 0.14.6)
|
42
42
|
concurrent-ruby (1.1.5)
|
43
|
-
connection_pool (2.2.
|
43
|
+
connection_pool (2.2.2)
|
44
44
|
crass (1.0.4)
|
45
45
|
database_cleaner (1.7.0)
|
46
46
|
diff-lcs (1.3)
|
data/README.md
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
[](https://travis-ci.org/hasghari/table_saw)
|
2
|
+
[](https://codeclimate.com/github/hasghari/table_saw/maintainability)
|
3
|
+
[](https://codeclimate.com/github/hasghari/table_saw/test_coverage)
|
4
|
+
|
2
5
|
# TableSaw
|
3
6
|
|
4
|
-
|
7
|
+
This gem creates a PSQL dump file (data only) from a Postgres database by only dumping a subset of data defined by a
|
8
|
+
manifest file.
|
5
9
|
|
6
|
-
|
10
|
+
It will automatically retrieve the foreign key dependencies of your tables as long as the foreign key constraints are
|
11
|
+
defined.
|
7
12
|
|
8
13
|
## Installation
|
9
14
|
|
@@ -23,17 +28,89 @@ Or install it yourself as:
|
|
23
28
|
|
24
29
|
## Usage
|
25
30
|
|
26
|
-
|
31
|
+
```
|
32
|
+
table-saw dump -m manifest.yml
|
33
|
+
```
|
34
|
+
|
35
|
+
The command above will read your configuration from `manifest.yml` and create a dump file `output.dump`. The database
|
36
|
+
connection properties can be supplied similar to the `pg_dump` tool provided by Postgres:
|
37
|
+
|
38
|
+
```
|
39
|
+
Usage:
|
40
|
+
table-saw dump -m, --manifest=MANIFEST
|
41
|
+
|
42
|
+
Options:
|
43
|
+
-u, [--url=URL] # Default value is $DATABASE_URL
|
44
|
+
-d, [--dbname=DBNAME] # Default value is $PGDATABASE
|
45
|
+
-h, [--host=HOST] # Default value is $PGHOST
|
46
|
+
-p, [--port=PORT] # Default value is $PGPORT
|
47
|
+
-U, [--user=USER] # Default value is $PGUSER
|
48
|
+
[--password=PASSWORD] # Default value is $PGPASSWORD
|
49
|
+
-m, --manifest=MANIFEST
|
50
|
+
-o, [--output=OUTPUT] # Default value is 'output.dump'
|
51
|
+
```
|
52
|
+
|
53
|
+
The manifest file describes which tables you want to dump from your Postgres database:
|
54
|
+
|
55
|
+
```yaml
|
56
|
+
variables:
|
57
|
+
author_id: 24
|
58
|
+
tables:
|
59
|
+
- table: books
|
60
|
+
query: "select * from books where author_id = %{author_id}"
|
61
|
+
```
|
62
|
+
|
63
|
+
This will only fetch records from the `books` table where `author_id = 24` and will also fetch the record from the
|
64
|
+
`authors` table where `id = 24`.
|
65
|
+
|
66
|
+
Assuming there is a `chapters` table with a foreign key reference of `book_id` to the `books` table, the above manifest
|
67
|
+
file will **not** automatically retrieve those records. If `chapters` records are also desired, there a couple ways to
|
68
|
+
accomplish this:
|
69
|
+
|
70
|
+
```yaml
|
71
|
+
variables:
|
72
|
+
author_id: 24
|
73
|
+
tables:
|
74
|
+
- table: books
|
75
|
+
query: "select * from books where author_id = %{author_id}"
|
76
|
+
has_many:
|
77
|
+
- chapters
|
78
|
+
```
|
79
|
+
|
80
|
+
or
|
81
|
+
|
82
|
+
```yaml
|
83
|
+
variables:
|
84
|
+
author_id: 24
|
85
|
+
tables:
|
86
|
+
- table: chapters
|
87
|
+
query: "select * from chapters inner join books on books.id = chapters.book_id where books.author_id = %{author_id}"
|
88
|
+
```
|
89
|
+
|
90
|
+
The output of the 2 manifest files above are exactly the same. The dump file will contain all the relevant records from
|
91
|
+
the `authors`, `books` and `chapters` tables.
|
92
|
+
|
93
|
+
Once your dump file has been created, you can import the data using `psql`:
|
94
|
+
|
95
|
+
```bash
|
96
|
+
table-saw dump -m manifest.yml -o chapters.dump
|
97
|
+
psql -h localhost -U postgres -d library < chapters.dump
|
98
|
+
```
|
27
99
|
|
28
100
|
## Development
|
29
101
|
|
30
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can
|
102
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can
|
103
|
+
also run `bin/console` for an interactive prompt that will allow you to experiment.
|
31
104
|
|
32
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
105
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
106
|
+
version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
|
107
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
33
108
|
|
34
109
|
## Contributing
|
35
110
|
|
36
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
111
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hasghari/table_saw. This project is intended
|
112
|
+
to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
|
113
|
+
[Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
37
114
|
|
38
115
|
## License
|
39
116
|
|
@@ -41,4 +118,5 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
41
118
|
|
42
119
|
## Code of Conduct
|
43
120
|
|
44
|
-
Everyone interacting in the TableSaw project’s codebases, issue trackers, chat rooms and mailing lists is expected to
|
121
|
+
Everyone interacting in the TableSaw project’s codebases, issue trackers, chat rooms and mailing lists is expected to
|
122
|
+
follow the [code of conduct](https://github.com/[USERNAME]/table_saw/blob/master/CODE_OF_CONDUCT.md).
|
data/exe/table-saw
CHANGED
@@ -16,14 +16,15 @@ class CLI < Thor
|
|
16
16
|
end
|
17
17
|
|
18
18
|
desc 'dump', 'Create a postgres dump file'
|
19
|
-
method_option :url, aliases: '-u', default: ENV['DATABASE_URL']
|
19
|
+
method_option :url, aliases: '-u', default: ENV['DATABASE_URL'],
|
20
|
+
desc: 'This option overrides all other connection properties.'
|
20
21
|
method_option :dbname, aliases: '-d', default: ENV['PGDATABASE']
|
21
22
|
method_option :host, aliases: '-h', default: ENV['PGHOST']
|
22
23
|
method_option :port, aliases: '-p', default: ENV['PGPORT']
|
23
24
|
method_option :user, aliases: '-U', default: ENV['PGUSER']
|
24
25
|
method_option :password, default: ENV['PGPASSWORD']
|
25
26
|
method_option :manifest, aliases: '-m', required: true
|
26
|
-
method_option :output, aliases: '-o', default: '
|
27
|
+
method_option :output, aliases: '-o', default: 'output.dump'
|
27
28
|
def dump
|
28
29
|
TableSaw.configure(options.to_hash)
|
29
30
|
records = TableSaw::BuildDependencyGraph.new(TableSaw::Manifest.instance).call
|
data/lib/table_saw/version.rb
CHANGED