pg_objects 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 +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +216 -0
- data/.rubocop_todo.yml +11 -0
- data/.travis.yml +8 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +81 -0
- data/LICENSE +21 -0
- data/README.md +63 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/pg_objects/config.rb +21 -0
- data/lib/pg_objects/db_object.rb +14 -0
- data/lib/pg_objects/logger.rb +13 -0
- data/lib/pg_objects/manager.rb +56 -0
- data/lib/pg_objects/parser.rb +9 -0
- data/lib/pg_objects/railtie.rb +10 -0
- data/lib/pg_objects/version.rb +3 -0
- data/lib/pg_objects.rb +15 -0
- data/lib/tasks/pg_objects_tasks.rake +12 -0
- data/pg_objects.gemspec +39 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6b6bf484846c2dff05a2cd1d35384961adbfc4783eeac290c5fee40795ba109b
|
4
|
+
data.tar.gz: d47658f719631137bcf977679caaeda0323bcdf6374e04fd0025d0fd5bd9db9c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f9e30e490f1a6fa0269d333ac7e90458f420dca07659ed40b5563c9b7c010f0b21d1066b9e4ac11a6c3b14a1471e96cd00456bb6c475667116b6603b09ea1922
|
7
|
+
data.tar.gz: 4f0d63c2b3a037d8e9721d1c2103e4d125c8384388a58f2336e504c8a6ca27c6e1b08bdf4b629cb91f5aa912a197678ef3e4e460e480a4ac8c402aa65eeab3ad
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,216 @@
|
|
1
|
+
# softened a bit with http://relaxed.ruby.style/rubocop.yml
|
2
|
+
|
3
|
+
require:
|
4
|
+
- rubocop-rspec
|
5
|
+
|
6
|
+
inherit_from: .rubocop_todo.yml
|
7
|
+
|
8
|
+
AllCops:
|
9
|
+
# EnabledByDefault: true
|
10
|
+
TargetRubyVersion: 2.5
|
11
|
+
# Cop names are not d§splayed in offense messages by default. Change behavior
|
12
|
+
# by overriding DisplayCopNames, or by giving the -D/--display-cop-names
|
13
|
+
# option.
|
14
|
+
DisplayCopNames: true
|
15
|
+
# Style guide URLs are not displayed in offense messages by default. Change
|
16
|
+
# behavior by overriding DisplayStyleGuide, or by giving the
|
17
|
+
# -S/--display-style-guide option.
|
18
|
+
DisplayStyleGuide: false
|
19
|
+
|
20
|
+
# Gems in consecutive lines should be alphabetically sorted
|
21
|
+
Bundler/OrderedGems:
|
22
|
+
TreatCommentsAsGroupSeparators: true
|
23
|
+
|
24
|
+
# Layout ######################################################################
|
25
|
+
# Checks that the closing brace in an array literal is either on the same line
|
26
|
+
# as the last array element, or a new line.
|
27
|
+
Layout/MultilineArrayBraceLayout:
|
28
|
+
Enabled: true
|
29
|
+
EnforcedStyle: symmetrical
|
30
|
+
|
31
|
+
# Checks that the closing brace in a hash literal is either on the same line as
|
32
|
+
# the last hash element, or a new line.
|
33
|
+
Layout/MultilineHashBraceLayout:
|
34
|
+
Enabled: true
|
35
|
+
EnforcedStyle: symmetrical
|
36
|
+
|
37
|
+
# Checks that the closing brace in a method call is either on the same line as
|
38
|
+
# the last method argument, or a new line.
|
39
|
+
Layout/MultilineMethodCallBraceLayout:
|
40
|
+
Enabled: true
|
41
|
+
EnforcedStyle: symmetrical
|
42
|
+
|
43
|
+
# Checks indentation of binary operations that span more than one line.
|
44
|
+
Layout/MultilineOperationIndentation:
|
45
|
+
Enabled: true
|
46
|
+
EnforcedStyle: indented
|
47
|
+
|
48
|
+
# Checks for padding/surrounding spaces inside string interpolation.
|
49
|
+
Layout/SpaceInsideStringInterpolation:
|
50
|
+
EnforcedStyle: no_space
|
51
|
+
Enabled: true
|
52
|
+
|
53
|
+
# Naming ######################################################################
|
54
|
+
Naming/UncommunicativeMethodParamName:
|
55
|
+
MinNameLength: 2
|
56
|
+
|
57
|
+
# Use the configured style when naming variables.
|
58
|
+
Naming/VariableName:
|
59
|
+
EnforcedStyle: snake_case
|
60
|
+
Enabled: true
|
61
|
+
|
62
|
+
# Style #######################################################################
|
63
|
+
# Use alias_method instead of alias.
|
64
|
+
Style/Alias:
|
65
|
+
EnforcedStyle: prefer_alias_method
|
66
|
+
Enabled: true
|
67
|
+
|
68
|
+
Style/AsciiComments:
|
69
|
+
Enabled: false
|
70
|
+
StyleGuide: http://relaxed.ruby.style/#styleasciicomments
|
71
|
+
|
72
|
+
# This cop checks that comment annotation keywords are written according
|
73
|
+
# to guidelines.
|
74
|
+
# Style/CommentAnnotation:
|
75
|
+
# Enabled: false
|
76
|
+
|
77
|
+
# Document classes and non-namespace modules.
|
78
|
+
Style/Documentation:
|
79
|
+
Enabled: false
|
80
|
+
|
81
|
+
# Checks if there is a magic comment to enforce string literals
|
82
|
+
Style/FrozenStringLiteralComment:
|
83
|
+
Enabled: false
|
84
|
+
|
85
|
+
Style/RegexpLiteral:
|
86
|
+
EnforcedStyle: mixed
|
87
|
+
Enabled: false
|
88
|
+
|
89
|
+
# Checks for proper usage of fail and raise.
|
90
|
+
Style/SignalException:
|
91
|
+
EnforcedStyle: only_raise
|
92
|
+
Enabled: true
|
93
|
+
|
94
|
+
# Check for the usage of parentheses around stabby lambda arguments.
|
95
|
+
Style/StabbyLambdaParentheses:
|
96
|
+
EnforcedStyle: require_parentheses
|
97
|
+
Enabled: true
|
98
|
+
|
99
|
+
# Checks if configured preferred methods are used over non-preferred.
|
100
|
+
Style/StringMethods:
|
101
|
+
PreferredMethods:
|
102
|
+
intern: to_sym
|
103
|
+
Enabled: true
|
104
|
+
|
105
|
+
# Checks for %q/%Q when single quotes or double quotes would do.
|
106
|
+
Style/UnneededPercentQ:
|
107
|
+
Enabled: false
|
108
|
+
|
109
|
+
# Metrics #####################################################################
|
110
|
+
|
111
|
+
# A calculated magnitude based on number of assignments,
|
112
|
+
# branches, and conditions.
|
113
|
+
# Metrics/AbcSize:
|
114
|
+
# Enabled: true
|
115
|
+
# Max: 58
|
116
|
+
|
117
|
+
# This cop checks if the length of a block exceeds some maximum value.
|
118
|
+
Metrics/BlockLength:
|
119
|
+
Enabled: false
|
120
|
+
|
121
|
+
# Avoid excessive block nesting.
|
122
|
+
# Metrics/BlockNesting:
|
123
|
+
# Enabled: true
|
124
|
+
# Max: 4
|
125
|
+
|
126
|
+
# Avoid classes longer than 100 lines of code.
|
127
|
+
Metrics/ClassLength:
|
128
|
+
Enabled: false
|
129
|
+
|
130
|
+
# A complexity metric that is strongly correlated to the number
|
131
|
+
# of test cases needed to validate a method.
|
132
|
+
# Metrics/CyclomaticComplexity:
|
133
|
+
# Enabled: true
|
134
|
+
# Max: 11
|
135
|
+
|
136
|
+
# Limit lines to 80 characters.
|
137
|
+
Metrics/LineLength:
|
138
|
+
Max: 140
|
139
|
+
|
140
|
+
# Avoid methods longer than 10 lines of code.
|
141
|
+
# Metrics/MethodLength:
|
142
|
+
# Max: 50
|
143
|
+
|
144
|
+
# Avoid modules longer than 100 lines of code.
|
145
|
+
Metrics/ModuleLength:
|
146
|
+
Enabled: false
|
147
|
+
|
148
|
+
# Avoid parameter lists longer than three or four parameters.
|
149
|
+
# Metrics/ParameterLists:
|
150
|
+
# Enabled: true
|
151
|
+
# Max: 8
|
152
|
+
|
153
|
+
# A complexity metric geared towards measuring complexity for a human reader.
|
154
|
+
# Metrics/PerceivedComplexity:
|
155
|
+
# Enabled: true
|
156
|
+
# Max: 13
|
157
|
+
|
158
|
+
# Lint ########################################################################
|
159
|
+
|
160
|
+
# This cop looks for use of the same name as outer local variables
|
161
|
+
# for block arguments or block local variables.
|
162
|
+
Lint/ShadowingOuterLocalVariable:
|
163
|
+
Enabled: false
|
164
|
+
|
165
|
+
# Rails #######################################################################
|
166
|
+
|
167
|
+
# Enables Rails cops.
|
168
|
+
Rails:
|
169
|
+
Enabled: false
|
170
|
+
|
171
|
+
# RSpec #######################################################################
|
172
|
+
|
173
|
+
# Checks for long example.
|
174
|
+
RSpec/ExampleLength:
|
175
|
+
Enabled: false
|
176
|
+
Max: 10
|
177
|
+
|
178
|
+
# Do not use should when describing your tests.
|
179
|
+
RSpec/ExampleWording:
|
180
|
+
Enabled: false
|
181
|
+
CustomTransform:
|
182
|
+
be: is
|
183
|
+
have: has
|
184
|
+
not: does not
|
185
|
+
IgnoredWords: []
|
186
|
+
|
187
|
+
# Checks the file and folder naming of the spec file.
|
188
|
+
RSpec/FilePath:
|
189
|
+
Enabled: true
|
190
|
+
CustomTransform:
|
191
|
+
RuboCop: rubocop
|
192
|
+
RSpec: rspec
|
193
|
+
|
194
|
+
RSpec/ImplicitExpect:
|
195
|
+
EnforcedStyle: should
|
196
|
+
Enabled: true
|
197
|
+
|
198
|
+
# incorrect treats shoulda-matchers
|
199
|
+
RSpec/ImplicitSubject:
|
200
|
+
Enabled: false
|
201
|
+
|
202
|
+
# Checks for `subject` definitions that come after `let` definitions.
|
203
|
+
RSpec/LeadingSubject:
|
204
|
+
Enabled: false
|
205
|
+
|
206
|
+
# Checks for explicitly referenced test subjects.
|
207
|
+
RSpec/NamedSubject:
|
208
|
+
Enabled: false
|
209
|
+
|
210
|
+
# Enforces the usage of the same method on all negative message expectations.
|
211
|
+
RSpec/NotToNot:
|
212
|
+
EnforcedStyle: not_to
|
213
|
+
Enabled: true
|
214
|
+
|
215
|
+
Style/IfUnlessModifier:
|
216
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2017-04-13 10:43:50 +0300 using RuboCop version 0.48.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
Style/GuardClause:
|
10
|
+
Exclude:
|
11
|
+
- pg_objects.gemspec
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pg_objects (0.1.0)
|
5
|
+
activerecord (~> 5.2.1)
|
6
|
+
rake-hooks (~> 1.2.3)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (5.2.1)
|
12
|
+
activesupport (= 5.2.1)
|
13
|
+
activerecord (5.2.1)
|
14
|
+
activemodel (= 5.2.1)
|
15
|
+
activesupport (= 5.2.1)
|
16
|
+
arel (>= 9.0)
|
17
|
+
activesupport (5.2.1)
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
+
i18n (>= 0.7, < 2)
|
20
|
+
minitest (~> 5.1)
|
21
|
+
tzinfo (~> 1.1)
|
22
|
+
arel (9.0.0)
|
23
|
+
ast (2.4.0)
|
24
|
+
byebug (10.0.2)
|
25
|
+
concurrent-ruby (1.0.5)
|
26
|
+
diff-lcs (1.3)
|
27
|
+
i18n (1.1.1)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
jaro_winkler (1.5.1)
|
30
|
+
minitest (5.11.3)
|
31
|
+
parallel (1.12.1)
|
32
|
+
parser (2.5.1.2)
|
33
|
+
ast (~> 2.4.0)
|
34
|
+
powerpack (0.1.2)
|
35
|
+
rainbow (3.0.0)
|
36
|
+
rake (10.5.0)
|
37
|
+
rake-hooks (1.2.3)
|
38
|
+
rake
|
39
|
+
rspec (3.8.0)
|
40
|
+
rspec-core (~> 3.8.0)
|
41
|
+
rspec-expectations (~> 3.8.0)
|
42
|
+
rspec-mocks (~> 3.8.0)
|
43
|
+
rspec-core (3.8.0)
|
44
|
+
rspec-support (~> 3.8.0)
|
45
|
+
rspec-expectations (3.8.2)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.8.0)
|
48
|
+
rspec-mocks (3.8.0)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.8.0)
|
51
|
+
rspec-support (3.8.0)
|
52
|
+
rubocop (0.59.2)
|
53
|
+
jaro_winkler (~> 1.5.1)
|
54
|
+
parallel (~> 1.10)
|
55
|
+
parser (>= 2.5, != 2.5.1.1)
|
56
|
+
powerpack (~> 0.1)
|
57
|
+
rainbow (>= 2.2.2, < 4.0)
|
58
|
+
ruby-progressbar (~> 1.7)
|
59
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
60
|
+
rubocop-rspec (1.30.0)
|
61
|
+
rubocop (>= 0.58.0)
|
62
|
+
ruby-progressbar (1.10.0)
|
63
|
+
thread_safe (0.3.6)
|
64
|
+
tzinfo (1.2.5)
|
65
|
+
thread_safe (~> 0.1)
|
66
|
+
unicode-display_width (1.4.0)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
ruby
|
70
|
+
|
71
|
+
DEPENDENCIES
|
72
|
+
bundler (~> 1.16)
|
73
|
+
byebug
|
74
|
+
pg_objects!
|
75
|
+
rake (~> 10.0)
|
76
|
+
rspec (~> 3.0)
|
77
|
+
rubocop (~> 0.59)
|
78
|
+
rubocop-rspec (~> 1.30)
|
79
|
+
|
80
|
+
BUNDLED WITH
|
81
|
+
1.16.6
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Denis Kiselyov
|
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,63 @@
|
|
1
|
+
[](https://travis-ci.org/marinazzio/pg_objects)
|
2
|
+
|
3
|
+
# PgObjects
|
4
|
+
|
5
|
+
Simple manager for PostgreSQL objects like triggers and functions.
|
6
|
+
|
7
|
+
Inspired by https://github.com/neongrau/rails_db_objects
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'pg_objects'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install pg_objects
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Put DB objects as CREATE (or CREATE OR UPDATE) queries in files to directory structure (default: *db/objects*).
|
28
|
+
|
29
|
+
You can control order of creating by using directive depends_on in SQL comment:
|
30
|
+
|
31
|
+
```sql
|
32
|
+
--!depends_on my_another_func
|
33
|
+
CREATE FUNCTION my_func()
|
34
|
+
...
|
35
|
+
```
|
36
|
+
|
37
|
+
The string after directive should be a name of file with dependency without extension.
|
38
|
+
|
39
|
+
## Configuration
|
40
|
+
|
41
|
+
Create file in *config/initializers* with the following content:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
PgObjects.configure do |config|
|
45
|
+
config.directories = ['db/objects', 'another/path/to/files'] # default: 'db/objects'
|
46
|
+
config.extensions = ['sql', 'txt'] # default: 'sql'
|
47
|
+
config.silent = false # whether to suppress output to console
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
Otherwise default values will be used.
|
52
|
+
|
53
|
+
Remember, you take care the specified directories are exist.
|
54
|
+
|
55
|
+
## Development
|
56
|
+
|
57
|
+
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.
|
58
|
+
|
59
|
+
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).
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/marinazzio/pg_objects.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'pg_objects'
|
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,21 @@
|
|
1
|
+
module PgObjects
|
2
|
+
class << self
|
3
|
+
def configure
|
4
|
+
yield config
|
5
|
+
end
|
6
|
+
|
7
|
+
def config
|
8
|
+
@config ||= Config.new
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Config
|
13
|
+
attr_accessor :directories, :extensions, :silent
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@directories = ['db/objects']
|
17
|
+
@extensions = ['sql']
|
18
|
+
@silent = false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module PgObjects
|
2
|
+
class DbObject
|
3
|
+
attr_reader :sql_query, :name, :dependencies
|
4
|
+
attr_accessor :status
|
5
|
+
|
6
|
+
def initialize(file_path)
|
7
|
+
@name = File.basename file_path, '.*'
|
8
|
+
@sql_query = File.read file_path
|
9
|
+
@dependencies = Parser.fetch_dependencies @sql_query
|
10
|
+
|
11
|
+
@status = :pending
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module PgObjects
|
2
|
+
class Manager
|
3
|
+
attr_reader :objects, :config, :log
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
raise UnsupportedAdapterError if ActiveRecord::Base.connection.adapter_name != 'PostgreSQL'
|
7
|
+
|
8
|
+
@objects = []
|
9
|
+
@config = PgObjects.config
|
10
|
+
@log = Logger.new(config.silent)
|
11
|
+
end
|
12
|
+
|
13
|
+
def load_files
|
14
|
+
config.directories.each do |dir|
|
15
|
+
Dir[File.join(dir, '**', "*.{#{config.extensions.join(',')}}")].each do |path|
|
16
|
+
@objects << PgObjects::DbObject.new(path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_objects
|
24
|
+
@objects.each { |obj| create_object obj }
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def create_object(obj)
|
30
|
+
return if obj.status == :done
|
31
|
+
raise CyclicDependencyError if obj.status == :processing
|
32
|
+
|
33
|
+
obj.status = :processing
|
34
|
+
|
35
|
+
create_dependencies(obj.dependencies)
|
36
|
+
|
37
|
+
log.write("creating #{obj.name}")
|
38
|
+
ActiveRecord::Base.connection.exec_query obj.sql_query
|
39
|
+
|
40
|
+
obj.status = :done
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_dependencies(dependencies)
|
44
|
+
dependencies.each { |dep_name| create_object find_object(dep_name) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def find_object(dep_name)
|
48
|
+
result = @objects.select { |obj| obj.name == dep_name }
|
49
|
+
|
50
|
+
raise AmbiguousDependencyError if result.size > 1
|
51
|
+
raise DependencyNotExistError if result.empty?
|
52
|
+
|
53
|
+
result[0]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/pg_objects.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'pg_objects/version'
|
2
|
+
require 'pg_objects/railtie' if defined?(Rails)
|
3
|
+
|
4
|
+
require 'pg_objects/config'
|
5
|
+
require 'pg_objects/db_object'
|
6
|
+
require 'pg_objects/logger'
|
7
|
+
require 'pg_objects/manager'
|
8
|
+
require 'pg_objects/parser'
|
9
|
+
|
10
|
+
module PgObjects
|
11
|
+
AmbiguousDependencyError = Class.new(StandardError)
|
12
|
+
CyclicDependencyError = Class.new(StandardError)
|
13
|
+
DependencyNotExistError = Class.new(StandardError)
|
14
|
+
UnsupportedAdapterError = Class.new(StandardError)
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
namespace :db do
|
2
|
+
desc 'Generate all the database objects of the current project'
|
3
|
+
task create_objects: :environment do
|
4
|
+
PgObjects::Manager.new.load_files.create_objects
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'rake/hooks'
|
9
|
+
|
10
|
+
before 'db:migrate' do
|
11
|
+
Rake::Task['db:create_objects'].invoke
|
12
|
+
end
|
data/pg_objects.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'pg_objects/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'pg_objects'
|
7
|
+
spec.version = PgObjects::VERSION
|
8
|
+
spec.authors = ['Denis Kiselyov']
|
9
|
+
spec.email = ['denis.kiselyov@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = %q(Simple manager for PostgreSQL objects like triggers and functions)
|
12
|
+
spec.homepage = 'https://github.com/marinazzio/pg_objects'
|
13
|
+
|
14
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
15
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
16
|
+
if spec.respond_to?(:metadata)
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
18
|
+
else
|
19
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
20
|
+
end
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = 'exe'
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_dependency 'activerecord', '~> 5.2.1'
|
32
|
+
spec.add_dependency 'rake-hooks', '~> 1.2.3'
|
33
|
+
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
spec.add_development_dependency 'rubocop', '~> 0.59'
|
38
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.30'
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pg_objects
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Denis Kiselyov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake-hooks
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.59'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.59'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.30'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.30'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- denis.kiselyov@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- ".rubocop_todo.yml"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Gemfile
|
124
|
+
- Gemfile.lock
|
125
|
+
- LICENSE
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- lib/pg_objects.rb
|
131
|
+
- lib/pg_objects/config.rb
|
132
|
+
- lib/pg_objects/db_object.rb
|
133
|
+
- lib/pg_objects/logger.rb
|
134
|
+
- lib/pg_objects/manager.rb
|
135
|
+
- lib/pg_objects/parser.rb
|
136
|
+
- lib/pg_objects/railtie.rb
|
137
|
+
- lib/pg_objects/version.rb
|
138
|
+
- lib/tasks/pg_objects_tasks.rake
|
139
|
+
- pg_objects.gemspec
|
140
|
+
homepage: https://github.com/marinazzio/pg_objects
|
141
|
+
licenses: []
|
142
|
+
metadata:
|
143
|
+
allowed_push_host: https://rubygems.org
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.7.6
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Simple manager for PostgreSQL objects like triggers and functions
|
164
|
+
test_files: []
|