prick 0.5.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67c64dcd2eb2d716544b81a7b17f15c8b42af6b863821f411596fac4b6868edd
4
- data.tar.gz: 178c2bd8cd8617fb4a10d6e1f76f15a601bb1341a2c64456a5c83ecc9eeff629
3
+ metadata.gz: 8fa13b0150bd8e2a403643947215116be13d78d33f053e15c766a258574cf79e
4
+ data.tar.gz: 8b817641aff64c1ad488ce7562ac03a26c8d2144b3bf79999ef0af0ae910d298
5
5
  SHA512:
6
- metadata.gz: 31fd38814ff54a3b535cabe371f1578abfcd025e749e9a9b1d18cdd454f7c74e5797b9166c4429f1bbda5ece50432bc0ace27d07a97e25591d1bae9648bb4b63
7
- data.tar.gz: 8c9bf98db283cb79a11edd4016339c74c84fc02517b9872b476e776ecf21e91ecde490e87689a8ae1a041ecd25836f92d5d145ac6e2452824480a8a9db5c65c5
6
+ metadata.gz: 5b0896b4d9d38984cee6f3a3d6481ed4b9607c54101a120aaa4344b701ed649fe7ef5ca25bcb1214aa1802700e80e0bee41aa47157039f4f2774825d0af04f44
7
+ data.tar.gz: e19f8f4b6529bc1463f01fdcb5077ddfd55fe970ac062ef8fbbfd79dd31d1c8f74dcef759222cfdbaf4890158ef6b7993ddeb369d8c0499ead2265f20073769a
data/exe/prick CHANGED
@@ -4,206 +4,163 @@ require 'prick.rb'
4
4
  require 'prick/program.rb'
5
5
 
6
6
  require 'shellopts'
7
- require 'indented_io'
8
7
 
9
8
  require 'tempfile'
10
9
 
11
10
  include ShellOpts
12
11
  include Prick
13
12
 
14
- PROGRAM = File.basename($0)
15
-
16
13
  SPEC = %(
17
- n,name=NAME
18
- C,directory=DIR
19
- h,help
20
- v,verbose
21
- q,quiet
22
- version
23
-
24
- init! u,user=USER
25
-
26
- info!
27
- list!
28
- list.releases! m,migrations c,cancelled
29
- list.migrations!
30
- list.upgrades! a,all
31
- list.cache!
32
-
33
- build! d,database=DATABASE C,nocache
34
- make! d,database=DATABASE C,nocache
35
- make.clean! a,all
36
- load! d,database=DATABASE
37
- save!
38
- drop! a,all
39
-
40
- diff! m,mark t,tables T,notables
41
- migrate!
42
-
43
- prepare! prepare.release! prepare.migration! prepare.schema! prepare.diff!
44
- include! include.feature!
45
- check!
46
-
47
- create! create.release! create.prerelease! create.feature!
48
- cancel! cancel.release!
49
-
50
- generate! generate.migration! generate.schema!
51
- upgrade!
52
- backup!
53
- restore!
54
- )
55
-
56
- USAGE = "Usage: #{PROGRAM} -h -v -n NAME -C DIR COMMAND" # FIXME: Why doesn't shellopts include PROGRAM?
57
-
58
- HELP = %(
59
- NAME
60
- prick - Database version management
61
-
62
- USAGE
63
- prick -v -n NAME -C DIR -h <command>
64
-
65
- OPTIONS
66
- -n, --name=NAME
14
+ -n,name=NAME
67
15
  Name of project. Defauls to the environment variable `PRICK_PROJECT` if
68
16
  set and else the name of the current directory
69
17
 
70
- -C, --directory=DIR
71
- Change to directory DIR before anything else
18
+ -C,directory=DIR
19
+ Change to directory DIR before doing anything else
72
20
 
73
- -h, --help
21
+ -h,help COMMAND...
74
22
  Print this page
75
23
 
76
- -v, --verbose
77
- Be verbose
78
-
79
- --version
80
- Print prick version
24
+ +v,verbose
25
+ Be verbose. Repeated --verbose options increase the verbosity level
81
26
 
82
- COMMANDS
83
- INITIALIZATION
84
- init --user=USER [DIR]
85
- Initialize a project in the given directory. DIR defaults to the
86
- current directory. The USER is the postgres user, it defaults to
87
- the project name
27
+ -q,quiet
28
+ Be quiet
88
29
 
89
- INFO COMMANDS
90
- info
30
+ --version
31
+ Print prick version
91
32
 
92
- list releases --migrations --cancelled
93
- list migrations
94
- list upgrades --all
95
- List releases/migrations/upgrades
33
+ init! -u,user=USER [DIR]
34
+ Initialize a project in the given directory. DIR defaults to the current
35
+ directory. The USER is the postgres user, it defaults to the project name
96
36
 
97
- BUILDING
98
- build -d DATABASE -C --nocache [TAG]
99
- Build the current database from the content in the schemas/ directory.
100
- With a tag the version is built into the associated versioned database.
101
- The result is saved to cache unless the -C option is given. The -d option
102
- overrides the default database
37
+ info!
38
+ Print project information
103
39
 
104
- make -d DATABASE -C --nocache [TAG]
105
- Loads the current database from cache if present and build it
106
- otherwise. With a tag, the version is built into the associated
107
- versioned database. The -C option ignores the cache and the -d option
108
- overrides the default database
40
+ list.releases! -m,migrations -c,cancelled
41
+ List releases. Include migration releases if the --migration option is
42
+ present and also include cancelled releases if the --cancelled option is
43
+ present
109
44
 
110
- make clean -a
111
- Drop versioned databases and remove cached and other temporary files.
112
- Also drop the project database if the -a option is given
113
-
114
- load -d DATABASE VERSION|FILE
115
- Load the cached version or the file into the associated versioned
116
- database. It is an error if the version hasn't been cached. The
117
- --database argument overrides the database
45
+ list.migrations!
46
+ List migrations
118
47
 
119
- save VERSION [FILE]
120
- Save the versioned database associated with version to the cache or the
121
- given file
48
+ list.upgrades! [FROM [TO]]
49
+ List available upgrades
122
50
 
123
- drop --all [DATABASE]
124
- Drop the given database or all versioned databases. The --all option also drops the project
125
- database
126
-
51
+ list.cache!
52
+ List cache files
53
+
54
+ build! -d,database=DATABASE -C,no-cache [TAG]
55
+ Build the current database from the content in the schemas/ directory.
56
+ With a tag the version is built into the associated versioned database
57
+ and the result is saved to cache unless the -C option is given. The -d
58
+ option overrides the default database
59
+
60
+ make! -d,database=DATABASE -C,no-cache [TAG]
61
+ Build the current database from the content in the schemas/ directory.
62
+ With a tag the associated versioned database is loaded from cache if
63
+ present. The -C option ignores the cache and the -d option overrides
64
+ the default database
65
+
66
+ make.clean! -a,all
67
+ Drop versioned databases and remove cached and other temporary files.
68
+ Also drop the project database if the -a option is given
69
+
70
+ load! -d,database=DATABASE VERSION|FILE
71
+ Load the cached version or the file into the associated versioned
72
+ database. It is an error if the version hasn't been cached. The --database
73
+ argument overrides the database
74
+
75
+ save! VERSION [FILE]
76
+ Save the versioned database associated with version to the cache or the
77
+ given file
78
+
79
+ drop! -a,all [DATABASE]
80
+ Drop the given database or all versioned databases. The --all option also
81
+ drops the project database
82
+
83
+ diff! -m,mark -t,tables -T,notables
127
84
  diff [FROM-DATABASE|FROM-VERSION [TO-DATABASE|TO-VERSION]]
128
- Create a schema diff between the given databases or versions. Default
129
- to-version is the current schema and default from-version is the base
130
- version of this branch/tag
85
+ Create a schema diff between the given databases or versions. Default
86
+ to-version is the current schema and default from-version is the base
87
+ version of this branch/tag
131
88
 
132
- migrate
133
- Not yet implemented
89
+ migrate!
90
+ Not yet implemented
134
91
 
135
- PREPARING RELEASES
136
- prepare release [FORK]
137
- Populate the current migration directory with migration files
92
+ prepare!
93
+ Prepare a release. Just a shorthand for 'prick prepare release'
138
94
 
139
- prepare feature NAME
140
- Create and populate a feature as a subdirectory of the current
141
- directory. Also prepares the current release directory
95
+ prepare.release! [FORK]
96
+ Populate the current migration directory with migration files
142
97
 
143
- prepare migration FROM
144
- Create and populate a migration directory
98
+ prepare.feature! NAME
99
+ Create and populate a feature as a subdirectory of the current directory.
100
+ Also prepares the current release directory
145
101
 
146
- prepare schema NAME
147
- Create and populate a new schema directory. Existing files and
148
- directories are kept
102
+ prepare.migration! [FROM]
103
+ Create and populate a migration directory
149
104
 
150
- prepare diff [VERSION]
105
+ prepare.schema! NAME
106
+ Create and populate a new schema directory. Existing files and
107
+ directories are kept
108
+
109
+ prepare.diff! [VERSION]
110
+ Not yet implemented
151
111
 
152
- include feature FEATURE
153
- Include the given feature in the current pre-release
112
+ include.feature! FEATURE
113
+ Include the given feature in the current pre-release
154
114
 
155
- check
156
- Check that the current migration applied to the base version yields the
157
- same result as loading the current schema
115
+ check!
116
+ Check that the current migration applied to the base version yields the
117
+ same result as loading the current schema
158
118
 
159
- CREATING RELEASES
160
- create release [RELEASE]
161
- Prepare a release and create release directory and migration file
162
- before tagging and branching to a release branch. The RELEASE argument
163
- can be left out if the current branch is a prerelease branch
119
+ create.release! [RELEASE]
120
+ Prepare a release and create release directory and migration file before
121
+ tagging and branching to a release branch. The RELEASE argument can be
122
+ left out if the current branch is a prerelease branch
164
123
 
165
- create prerelease RELEASE
166
- Prepare a release and create release directory and migration file
167
- before branching to a prerelease branch
168
-
169
- create feature NAME
170
- Prepare a feature before branching to a feature branch
124
+ create.prerelease! RELEASE
125
+ Prepare a release and create release directory and migration file before
126
+ branching to a prerelease branch
171
127
 
172
- cancel release RELEASE
173
- Cancel a release. Since tags are immutable, the release is cancelled by
174
- added a special cancel-tag to the release that makes prick ignore it
128
+ create.feature! NAME
129
+ Prepare a feature before branching to a feature branch
175
130
 
176
- DEPLOYING RELEASES
177
- generate migration
178
- generate schema
179
- Create a PostgreSQL script to migrate or create the database
131
+ cancel!
132
+ Cancel a release. Just a shorthand for 'prick cancel release'
133
+
134
+ cancel.release!
135
+ Cancel a release. Since tags are immutable, the release is cancelled by
136
+ added a special cancel-tag to the release that makes prick ignore it
180
137
 
181
- upgrade
182
- Migrate the database to match the current schema
138
+ generate.migration!
139
+ Create a script to migrate the database
183
140
 
184
- backup [FILE]
185
- Saves a backup of the database to the given file or to the var/spool
186
- directory
141
+ generate.schema!
142
+ Create a script to create the database
187
143
 
188
- restore [FILE]
189
- Restore the database from the given backup file or from the latest
190
- backup in the var/spool directory
144
+ upgrade!
145
+ Migrate the database to match the current schema
146
+
147
+ backup! [FILE]
148
+ Saves a backup of the database to the given file or to the var/spool
149
+ directory
150
+
151
+ restore! [FILE]
152
+ Restore the database from the given backup file or from the latest backup
153
+ in the var/spool directory
191
154
  )
192
155
 
193
156
 
194
- opts, args = ShellOpts.as_struct(SPEC, ARGV)
157
+
158
+ opts, args = ShellOpts.process(SPEC, ARGV)
195
159
 
196
160
  # Handle --help
197
- if opts.help?
198
- begin
199
- file = Tempfile.new("prick")
200
- file.puts HELP.split("\n").map { |l| l.sub(/^ /, "") }
201
- file.flush
202
- system "less #{file.path}"
203
- ensure
204
- file.close
205
- end
206
- exit
161
+ if opts.help?
162
+ ShellOpts.help
163
+ exit
207
164
  end
208
165
 
209
166
  # Handle --version
@@ -214,7 +171,7 @@ end
214
171
 
215
172
  begin
216
173
  # Honor -C option
217
- if opts.directory
174
+ if opts.directory?
218
175
  if File.exist?(opts.directory)
219
176
  begin
220
177
  Dir.chdir(opts.directory)
@@ -232,8 +189,8 @@ begin
232
189
  # Handle init command
233
190
  if opts.subcommand == :init
234
191
  directory = args.expect(0..1)
235
- name = opts.name || directory || File.basename(Dir.getwd)
236
- user = opts.init.user || name
192
+ name = opts.name || (directory && File.basename(directory)) || File.basename(Dir.getwd)
193
+ user = opts.init!.user || name
237
194
  program.init(name, user, directory || ".")
238
195
  exit 0
239
196
  end
@@ -247,40 +204,59 @@ begin
247
204
  # TODO: Check for dirty detached head
248
205
 
249
206
  # Expect a sub-command
250
- opts.subcommand? or raise Prick::Error, "Subcomand expected"
207
+ opts.subcommand or raise Prick::Error, "Subcomand expected"
251
208
 
252
209
  case opts.subcommand
253
210
  when :info
254
211
  args.expect(0)
255
212
  program.info
256
213
 
214
+ when :list
215
+ command = opts.list!
216
+ case command.subcommand
217
+ when :releases;
218
+ obj = command.releases!
219
+ program.list_releases(migrations: obj.migrations?, cancelled: obj.cancelled?)
220
+ when :migrations; program.list_migrations
221
+ when :upgrades; program.list_upgrades(*args.expect(0..2).compact)
222
+ when :cache;
223
+ args.expect(0)
224
+ program.list_cache
225
+ when NilClass; raise Prick::Error, "list requires a releases|migrations|upgrades sub-command"
226
+ else
227
+ raise Prick::Internal, "Subcommand #{opts.subcommand}.#{command.subcommand} is not matched"
228
+ end
229
+
257
230
  when :build
258
231
  version = args.expect(0..1)
259
- program.build(opts.build.database, version, opts.build.nocache)
232
+ program.build(opts.build!.database, version, opts.build!.no_cache?)
260
233
 
261
234
  when :make
262
- command = opts.make
235
+ command = opts.make!
263
236
  case command.subcommand
264
237
  when :clean
265
238
  args.expect(0)
266
- program.make_clean(command.clean.all)
239
+ program.make_clean(command.clean!.all?)
267
240
  else
268
241
  version = args.expect(0..1)
269
- program.make(opts.make.database, version, opts.make.nocache)
242
+ program.make(opts.make!.database, version, opts.make!.no_cache?)
270
243
  end
271
244
 
272
245
  when :load
273
246
  version_or_file = args.expect(1)
274
- program.load(opts.load.database, version_or_file)
247
+ program.load(opts.load!.database, version_or_file)
275
248
 
276
249
  when :save
277
250
  version, file = args.expect(1..2)
278
251
  program.save(version, file)
279
252
 
253
+ when :drop
254
+ program.drop(args.expect(0..1), opts.drop!.all?)
255
+
280
256
  when :diff
281
- mark = opts.diff.mark
282
- tables = opts.diff.tables
283
- no_tables = opts.diff.notables
257
+ mark = opts.diff!.mark
258
+ tables = opts.diff!.tables
259
+ no_tables = opts.diff!.notables
284
260
  tables.nil? && no_tables.nil? || tables ^ no_tables or
285
261
  raise Error, "--tables and --no-tables options are exclusive"
286
262
  select = tables ? :tables : (no_tables ? :no_tables : :all)
@@ -290,31 +266,12 @@ begin
290
266
  when :migrate
291
267
  raise NotYet
292
268
 
293
- when :drop
294
- program.drop(args.expect(0..1), opts.drop.all)
295
-
296
- when :list
297
- command = opts.list
298
- case command.subcommand
299
- when :releases;
300
- obj = command.releases
301
- program.list_releases(migrations: obj.migrations?, cancelled: obj.cancelled?)
302
- when :migrations; program.list_migrations
303
- when :upgrades; program.list_upgrades(*args.expect(0..2).compact)
304
- when :cache;
305
- args.expect(0)
306
- program.list_cache
307
- when NilClass; raise Prick::Error, "list requires a releases|migrations|upgrades sub-command"
308
- else
309
- raise Prick::Internal, "Subcommand #{opts.subcommand}.#{command.subcommand} is not matched"
310
- end
311
-
312
269
  when :prepare
313
- cmd = opts.prepare.subcommand || :release
270
+ cmd = opts.prepare!.subcommand || :release
314
271
  case cmd
315
272
  when :release; program.prepare_release(args.expect(0..1))
316
- when :feature; raise NotYet
317
- when :migration; program.prepare_migration(args.expect(1))
273
+ when :feature; program.prepare_feature(args.expect(1))
274
+ when :migration; program.prepare_migration(args.expect(0..1))
318
275
  when :schema; program.prepare_schema(args.expect(1))
319
276
  when :diff; program.prepare_diff(args.expect(0..1))
320
277
  else
@@ -322,7 +279,7 @@ begin
322
279
  end
323
280
 
324
281
  when :include
325
- cmd = opts.include.subcommand || :feature
282
+ cmd = opts.include!.subcommand || :feature
326
283
  case cmd
327
284
  when :feature; program.include_feature(args.expect(1))
328
285
  else
@@ -334,7 +291,7 @@ begin
334
291
  program.check
335
292
 
336
293
  when :create
337
- cmd = opts.create.subcommand || :release
294
+ cmd = opts.create!.subcommand || :release
338
295
  case cmd
339
296
  when :release; program.create_release(args.expect(0..1))
340
297
  when :prerelease; program.create_prerelease(args.expect(0..1))
@@ -344,20 +301,20 @@ begin
344
301
  end
345
302
 
346
303
  when :cancel
347
- cmd = opts.cancel.subcommand
304
+ cmd = opts.cancel!.subcommand
348
305
  case cmd
349
306
  when :release; program.cancel_release(args.expect(1))
350
- when nil; raise Prick::Error, "'cancel' subcommand require a release argument"
307
+ when nil; raise Prick::Error, "'cancel' subcommand requires a release argument"
351
308
  else
352
309
  raise Prick::Internal, "Subcommand #{opts.subcommand}.#{cmd} is not matched"
353
310
  end
354
311
 
355
312
  when :generate
356
- cmd = opts.generate.subcommand
313
+ cmd = opts.generate!.subcommand
357
314
  case cmd
358
315
  when :schema; program.generate_schema
359
316
  when :migration; program.generate_migration
360
- when nil; raise Prick::Error, "'genrate' subcommand require a 'schema' or 'migration' argument"
317
+ when nil; raise Prick::Error, "'generate' subcommand requires a 'schema' or 'migration' argument"
361
318
  else
362
319
  raise Prick::Internal, "Subcommand #{opts.subcommand}.#{cmd} is not matched"
363
320
  end
@@ -381,3 +338,56 @@ rescue Prick::Error => ex
381
338
  ShellOpts.error(ex.message)
382
339
  end
383
340
 
341
+ __END__
342
+
343
+ # Awaits support for sections in ShellOpts
344
+ HELP = %(
345
+ OPTIONS
346
+ -n, --name=NAME
347
+ -C, --directory=DIR
348
+ -h, --help
349
+ -v, --verbose
350
+ --version
351
+
352
+ COMMANDS
353
+ INITIALIZATION
354
+ init --user=USER [DIR]
355
+
356
+ INFO COMMANDS
357
+ info
358
+ list releases --migrations --cancelled
359
+ list migrations
360
+ list upgrades --all
361
+
362
+ BUILDING
363
+ build -d DATABASE -C --nocache [TAG]
364
+ make -d DATABASE -C --nocache [TAG]
365
+ make clean -a
366
+ load -d DATABASE VERSION|FILE
367
+ save VERSION [FILE]
368
+ drop --all [DATABASE]
369
+ diff [FROM-DATABASE|FROM-VERSION [TO-DATABASE|TO-VERSION]]
370
+ migrate
371
+
372
+ PREPARING RELEASES
373
+ prepare release [FORK]
374
+ prepare feature NAME
375
+ prepare migration FROM
376
+ prepare schema NAME
377
+ prepare diff [VERSION]
378
+ include feature FEATURE
379
+ check
380
+
381
+ CREATING RELEASES
382
+ create release [RELEASE]
383
+ create prerelease RELEASE
384
+ create feature NAME
385
+ cancel release RELEASE
386
+
387
+ DEPLOYING RELEASES
388
+ generate migration
389
+ generate schema
390
+ upgrade
391
+ backup [FILE]
392
+ restore [FILE]
393
+ )
data/lib/prick.rb CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
+ #$LOAD_PATH.unshift("/home/clr/prj/shellopts/lib")
3
+
2
4
  # 'semantic' is required here instead of in prick/version.rb to avoid having Gem depend on it
3
5
  require "semantic"
4
6
 
@@ -25,7 +27,5 @@ require "prick/version.rb"
25
27
  require "ext/fileutils.rb"
26
28
  require "ext/shortest_path.rb"
27
29
 
28
- require "indented_io"
29
-
30
30
  module Prick
31
31
  end
data/lib/prick/builder.rb CHANGED
@@ -20,6 +20,8 @@ module Prick
20
20
  # If a directory doesn't contain a build resource, the resources in the
21
21
  # directory are built in alphabetic order
22
22
  #
23
+ # Build SQL scripts are executed with search path set to containing schema
24
+ #
23
25
  class Builder
24
26
  attr_reader :database
25
27
  attr_reader :directory
@@ -57,11 +59,11 @@ module Prick
57
59
  Dir.chdir(dir) { yield(file) }
58
60
  end
59
61
 
60
- def do_sql(path)
62
+ def do_sql(path, schema: nil)
61
63
  # puts "do_sql(#{path})"
62
64
  do_dir(path) { |file|
63
65
  if @execute
64
- Rdbms.exec_file(database.name, file, user: database.user)
66
+ Rdbms.exec_file(database.name, file, user: database.user, schema: schema)
65
67
  else
66
68
  @lines += IO.readlines(file).map(&:chomp)
67
69
  end
@@ -159,6 +161,12 @@ module Prick
159
161
  end
160
162
 
161
163
  def self.yml_file(directory) File.join(directory, "build") + ".yml" end
164
+
165
+ protected
166
+ def do_sql(path)
167
+ schema = Dir.getwd.sub(/^.*schema\/([^\/]+)(?:\/.*)?$/, '\1')
168
+ super(path, schema: schema)
169
+ end
162
170
  end
163
171
  end
164
172
 
@@ -1,6 +1,4 @@
1
1
 
2
- #require "prick/ensure.rb"
3
-
4
2
  module Prick
5
3
  class Database
6
4
  attr_reader :name
data/lib/prick/program.rb CHANGED
@@ -25,7 +25,7 @@ module Prick
25
25
  def init(name, user, directory)
26
26
  !Project.exist?(directory) or raise Error, "Directory #{directory} is already initialized"
27
27
  Project.create(name, user, directory)
28
- if name != File.basename(directory)
28
+ if name != directory
29
29
  mesg "Initialized project #{name} in #{directory}"
30
30
  else
31
31
  mesg "Initialized project #{name}"
@@ -46,12 +46,23 @@ module Prick
46
46
  puts " Schema version : #{sv}" + (sv != bv ? " (mismatch)" : "")
47
47
  end
48
48
 
49
+ def list_releases(migrations: false, cancelled: false)
50
+ raise NotYet
51
+ end
52
+
53
+ def list_migrations
54
+ raise NotYet
55
+ end
56
+
57
+ def list_upgrades(from = nil, to = nil)
58
+ raise NotYet
59
+ end
60
+
49
61
  def list_cache
50
62
  project.cache.list.each { |l| puts l }
51
63
  end
52
64
 
53
65
  def build(database, version, nocache)
54
- check_owned(database) if database
55
66
  into_mesg = database && "into #{database}"
56
67
  version_mesg = version ? "v#{version}" : "current schema"
57
68
  version &&= Version.new(version)
@@ -63,7 +74,6 @@ module Prick
63
74
  end
64
75
 
65
76
  def make(database, version, nocache)
66
- check_owned(database) if database
67
77
  version &&= Version.new(version)
68
78
  version.nil? || Git.tag?(version) or raise Error, "Can't find tag v#{version}"
69
79
  if !nocache && version && project.cache.exist?(version)
@@ -74,7 +84,7 @@ module Prick
74
84
  end
75
85
 
76
86
  def make_clean(all)
77
- project.cache.clean.each { |file| puts "Removed cache file #{File.basename(file)}" }
87
+ project.cache.clean.each { |file| mesg "Removed cache file #{File.basename(file)}" }
78
88
  drop(nil, all)
79
89
  end
80
90
 
@@ -135,10 +145,26 @@ module Prick
135
145
  end
136
146
  end
137
147
 
148
+ def migrate
149
+ raise NotYet
150
+ end
151
+
138
152
  def prepare_release(fork)
139
153
  project.prepare_release(fork)
140
154
  end
141
155
 
156
+ def prepare_feature(name)
157
+ raise NotYet
158
+ end
159
+
160
+ def prepare_migration(from = nil)
161
+ raise NotYet
162
+ end
163
+
164
+ def prepare_schema(name)
165
+ project.prepare_schema(name)
166
+ end
167
+
142
168
  def prepare_diff(version = nil)
143
169
  # Helpful check to ensure the user has built the current version
144
170
  # Diff.same?(to_db, database) or
@@ -153,6 +179,20 @@ module Prick
153
179
  end
154
180
  end
155
181
 
182
+ def include(name)
183
+ raise NotYet
184
+ end
185
+
186
+ def check
187
+ version ||=
188
+ if project.prerelease? || project.migration?
189
+ project.branch.base_version
190
+ else
191
+ project.branch.version
192
+ end
193
+ project.check_migration(version)
194
+ end
195
+
156
196
  def create_release(version = nil)
157
197
  if project.prerelease_branch?
158
198
  raise NotYet
@@ -164,6 +204,18 @@ module Prick
164
204
  mesg "Created release v#{project.head.version}"
165
205
  end
166
206
 
207
+ def create_prerelease(version = nil)
208
+ raise NotYet
209
+ end
210
+
211
+ def create_feature(name)
212
+ raise NotYet
213
+ end
214
+
215
+ def cancel(version)
216
+ raise NotYet
217
+ end
218
+
167
219
  def generate_schema
168
220
  project.generate_schema
169
221
  end
@@ -172,6 +224,10 @@ module Prick
172
224
  project.generate_migration
173
225
  end
174
226
 
227
+ def upgrade
228
+ raise NotYet
229
+ end
230
+
175
231
  # TODO: Create a Backup class and a Project#backup_store object
176
232
  def backup(file = nil)
177
233
  file = file || File.join(SPOOL_DIR, "#{project.name}-#{Time.now.utc.strftime("%Y%m%d-%H%M%S")}.sql.gz")
data/lib/prick/project.rb CHANGED
@@ -98,8 +98,6 @@ module Prick
98
98
  Project.new(state.name, state.user, branch)
99
99
  end
100
100
 
101
- # def checkout(branch_or_tag) end
102
-
103
101
  def build(database = self.database, version: nil)
104
102
  database.clean
105
103
  if version
@@ -118,17 +116,6 @@ module Prick
118
116
  self
119
117
  end
120
118
 
121
- # def make(database = self.database, version: nil)
122
- # database.clean
123
- # if cache.exist?(version)
124
- # load(database, version: version)
125
- # else
126
- # build(database, version: version)
127
- # cache.save(database, version) if version
128
- # end
129
- # self
130
- # end
131
-
132
119
  def load(database = self.database, version: nil, file: nil)
133
120
  version.nil? ^ file.nil? or raise Internal, "Need exactly one of :file and :version to be defined"
134
121
  database.clean
@@ -175,6 +162,16 @@ module Prick
175
162
  self
176
163
  end
177
164
 
165
+ def prepare_schema(name, commit: true)
166
+ path = File.join(SCHEMA_DIR, name)
167
+ FileUtils.mkdir_p(path)
168
+ Git.add Share.cp("schema/schema.sql", path, clobber: false, templates: { 'SCHEMA' => name })
169
+ Git.add Share.cp("schema/build.yml", path, clobber: false)
170
+ File.open(Schema.yml_file, "a") { |f| f.write("- #{name}\n") }
171
+ Git.add(Schema.yml_file)
172
+ submit "Added schema #{name}", commit
173
+ end
174
+
178
175
  def prepare_diff(from_version = version)
179
176
  begin
180
177
  from_name = "#{name}-base"
data/lib/prick/rdbms.rb CHANGED
@@ -1,30 +1,29 @@
1
1
  require 'prick/command.rb'
2
- #require 'prick/ensure.rb'
3
2
 
4
3
  require 'csv'
5
4
 
6
5
  module Prick
7
6
  module Rdbms
8
- # extend Ensure
9
-
10
7
  ### EXECUTE SQL
11
8
 
12
- # Execute the SQL statement and return stdout as an array of tuples. FIXME:
13
- # SQL can't contain '"'
14
- def self.exec_sql(db, sql, user: ENV['USER'])
9
+ # Execute the SQL statement and return stdout as an array of tuples
10
+ def self.exec_sql(db, sql, user: ENV['USER'], schema: nil)
11
+ schema ||= "public"
15
12
  stdout = Command.command %(
16
13
  {
17
14
  echo "set role #{user};"
18
- echo "set search_path to public;"
19
- echo "#{sql}"
15
+ echo "set search_path to #{schema};"
16
+ cat <<'EOF'
17
+ #{sql}
18
+ EOF
20
19
  } | psql --csv --tuples-only --quiet -v ON_ERROR_STOP=1 -d #{db}
21
20
  )
22
21
  CSV.new(stdout.join("\n")).read
23
22
  end
24
23
 
25
24
  # Execute the given file and return stdout as an array of tuples
26
- def self.exec_file(db, file, user: ENV['USER'])
27
- self.exec_sql(db, File.read(file), user: user)
25
+ def self.exec_file(db, file, user: ENV['USER'], schema: nil)
26
+ self.exec_sql(db, File.read(file), user: user, schema: schema)
28
27
  end
29
28
 
30
29
  # Execute the SQL statement and return the result as an array of record tuples
@@ -132,16 +131,6 @@ module Prick
132
131
  data_opt = (data ? "" : "--schema-only")
133
132
  Command.command "pg_dump --no-owner #{data_opt} #{db} | gzip --to-stdout >#{file}"
134
133
  end
135
-
136
- private
137
- @ensure_states = {
138
- exist_user: [:create_user, :drop_user],
139
- exist_database: [
140
- lambda { |this, db, user| this.ensure_state(:exist_user, user) },
141
- lambda { |this, db, user| this.create_database(db, owner: user) },
142
- :drop_database
143
- ]
144
- }
145
134
  end
146
135
  end
147
136
 
data/lib/prick/schema.rb CHANGED
@@ -7,9 +7,10 @@ module Prick
7
7
  BUILD_SQL_FILE = BUILD_BASE_NAME + ".sql"
8
8
  BUILD_YML_FILE = BUILD_BASE_NAME + ".yml"
9
9
 
10
- # Note this models the SCHEMAS_DIR directory, not a database schema
10
+ # Note this models the SCHEMA_DIR directory, not a database schema
11
11
  class Schema
12
- def yml_file() SchemaBuilder.yml_file(SCHEMA_DIR) end
12
+ def yml_file() self.class.yml_file end
13
+ def self.yml_file() SchemaBuilder.yml_file(SCHEMA_DIR) end
13
14
 
14
15
  def version() SchemaVersion.load end
15
16
  def version=(version) SchemaVersion.new(version).write end
data/lib/prick/version.rb CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # Required by gem
6
6
  module Prick
7
- VERSION = "0.5.0"
7
+ VERSION = "0.10.0"
8
8
  end
9
9
 
10
10
  # Project related code starts here
data/prick.gemspec CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
+ #$LOAD_PATH.unshift("/home/clr/prj/shellopts/lib")
3
+
2
4
  #lib = File.expand_path("../lib", __FILE__)
3
5
  #$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  #require "prick/version"
@@ -29,7 +31,7 @@ Gem::Specification.new do |spec|
29
31
  spec.require_paths = ["lib"]
30
32
 
31
33
  # spec.add_dependency "pg"
32
- spec.add_dependency "shellopts", "2.0.0.pre.11"
34
+ spec.add_dependency "shellopts", "2.0.0.pre.14"
33
35
  spec.add_dependency "semantic"
34
36
  spec.add_dependency "indented_io"
35
37
  end
@@ -1,5 +1,3 @@
1
1
 
2
2
  drop schema if exists [<SCHEMA>] cascade;
3
3
  create schema [<SCHEMA>];
4
-
5
- set search_path to [<SCHEMA>];
@@ -1,5 +1,3 @@
1
1
 
2
2
  drop schema if exists prick cascade;
3
3
  create schema prick;
4
-
5
- set search_path to prick;
@@ -1,7 +1,6 @@
1
1
  # Default schema files
2
2
  #
3
3
  ---
4
- - schema
5
4
  - roles
6
5
  - types
7
6
  - tables
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-27 00:00:00.000000000 Z
11
+ date: 2021-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shellopts
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0.pre.11
19
+ version: 2.0.0.pre.14
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.0.pre.11
26
+ version: 2.0.0.pre.14
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: semantic
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -133,7 +133,6 @@ files:
133
133
  - share/schema/schema/prick/tables.sql
134
134
  - share/schema/schema/public/.keep
135
135
  - share/schema/schema/public/build.yml
136
- - share/schema/schema/public/schema.sql
137
136
  - test_assorted
138
137
  - test_feature
139
138
  - test_refactor
@@ -156,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
155
  - !ruby/object:Gem::Version
157
156
  version: '0'
158
157
  requirements: []
159
- rubygems_version: 3.1.2
158
+ rubygems_version: 3.1.4
160
159
  signing_key:
161
160
  specification_version: 4
162
161
  summary: A release control and management system for postgresql
@@ -1,3 +0,0 @@
1
- set search_path to public;
2
-
3
-