prick 0.41.0 → 0.42.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/prick +40 -28
- data/lib/prick/constants.rb +26 -12
- data/lib/prick/state.rb +14 -5
- data/lib/prick/subcommand/prick-init.rb +1 -0
- data/lib/prick/version.rb +1 -1
- data/lib/prick-command.rb +0 -1
- data/lib/prick.rb +11 -12
- 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: b81d387c058ac6fc795be670066afa602c818d70668ad6fcb34e5fccab9860dd
|
4
|
+
data.tar.gz: 2d49b6f26b4b3a38a5d5969f97b545014257a16c3844100561ca3d96404eaa3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1edeeee6725fb7f8c2826a5e8cdb5a574c64689200ae7b19f7b6e466b201823eb6a76d119787484eff9d5080eeafe0b64015502fe19d88c26bd5a867cb40f209
|
7
|
+
data.tar.gz: 4bc01bb60d5a034457a40a766534c11755bb4471c315113125d119c2819184e762be82eb63b14a92a423fa8078a7bbbac552c7d4873cc49d09a59ed1ccb63bae
|
data/exe/prick
CHANGED
@@ -273,47 +273,59 @@ def parse_database_args(state, args)
|
|
273
273
|
[username, database, environment]
|
274
274
|
end
|
275
275
|
|
276
|
+
require_relative '../lib/prick-command.rb'
|
277
|
+
include Prick
|
278
|
+
|
276
279
|
begin
|
277
280
|
# Parse command line
|
278
281
|
opts, args = ShellOpts.process(SPEC, ARGV, exception: true)
|
279
282
|
|
283
|
+
# Expect a sub-command. TODO: Make this a built-in in ShellOpts#subcommand!
|
284
|
+
cmd = opts.subcommand! or Prick.error "Subcomand expected"
|
285
|
+
|
286
|
+
# Setup verbose and quiet
|
287
|
+
$verbose = opts.verbose?
|
288
|
+
$quiet = opts.quiet?
|
289
|
+
|
280
290
|
# Honor -C option
|
281
291
|
begin
|
282
|
-
|
292
|
+
if opts.directory?
|
293
|
+
Dir.chdir(opts.directory)
|
294
|
+
end
|
283
295
|
rescue Errno::ENOENT
|
284
296
|
raise ShellOpts::Error, "Can't cd to '#{opts.directory}'"
|
285
297
|
end
|
286
|
-
rescue ShellOpts::Error => ex
|
287
|
-
ShellOpts.error(ex.message)
|
288
|
-
end
|
289
|
-
|
290
|
-
# Require prick only after -C directory option because some constants depends
|
291
|
-
# on the current directory
|
292
|
-
require_relative '../lib/prick-command.rb'
|
293
|
-
include Prick
|
294
|
-
|
295
|
-
begin
|
296
|
-
# Handle verbose and quiet
|
297
|
-
$verbose = opts.verbose?
|
298
|
-
$quiet = opts.quiet?
|
299
|
-
|
300
|
-
# Expect a sub-command. TODO: Make this a built-in in ShellOpts#subcommand!
|
301
|
-
cmd = opts.subcommand! or Prick.error "Subcomand expected"
|
302
|
-
|
303
|
-
# Handle -p, -e, and -c. TODO: Take -C into account for relative paths. Low-hanging fruit
|
304
|
-
project_file = opts.project_file || PRICK_PROJECT_PATH
|
305
|
-
environment_file = opts.environment_file || PRICK_ENVIRONMENT_PATH
|
306
|
-
reflections_file = opts.reflections_file || REFLECTIONS_PATH
|
307
|
-
state_file = opts.state_file || PRICK_STATE_PATH
|
308
|
-
fox_state_file = opts.fox_state_file || FOX_STATE_PATH
|
309
298
|
|
310
299
|
# Process init command and exit
|
311
300
|
if opts.subcommand == :init!
|
312
|
-
|
301
|
+
# Set project directory before loading constants.rb to prevent it from
|
302
|
+
# searching in vain for the yet-to-be-created project directory
|
303
|
+
Prick.const_set("PRICK_DIR", args.expect(0..1) || ".")
|
304
|
+
|
305
|
+
# Load remaining constants that may depend on PRICK_DIR
|
306
|
+
require_relative '../lib/prick/constants.rb'
|
307
|
+
|
308
|
+
# Initialize project
|
309
|
+
dir, name = Prick::SubCommand.init(PRICK_PROJECT_FILE, PRICK_DIR, cmd.name, cmd.title)
|
313
310
|
Prick.mesg "Initialized Prick project '#{name}' in #{File.absolute_path(dir)}/"
|
311
|
+
|
312
|
+
# Exit
|
314
313
|
exit
|
315
314
|
end
|
316
315
|
|
316
|
+
# Find project directory and initialize constants
|
317
|
+
require_relative '../lib/prick/constants.rb'
|
318
|
+
|
319
|
+
# Switch to project directory
|
320
|
+
Dir.chdir PRICK_DIR
|
321
|
+
|
322
|
+
# Handle -p, -e, and -c. TODO: Take -C into account for relative paths. Low-hanging fruit
|
323
|
+
project_path = opts.project_file || PRICK_PROJECT_PATH
|
324
|
+
environment_path = opts.environment_file || PRICK_ENVIRONMENT_PATH
|
325
|
+
reflections_path = opts.reflections_file || REFLECTIONS_PATH
|
326
|
+
state_path = opts.state_file || PRICK_STATE_PATH
|
327
|
+
fox_state_path = opts.fox_state_file || FOX_STATE_PATH
|
328
|
+
|
317
329
|
# Check for prick project
|
318
330
|
if ![:teardown!, :clean!].include?(opts.subcommand) || args.size == 0
|
319
331
|
# We test for the presense of the schema directory to verify we're in a
|
@@ -321,11 +333,11 @@ begin
|
|
321
333
|
# they can be placed elsewhere. TODO: This require us to check for project file manually
|
322
334
|
# File.directory? "schema" or Prick.error "Not in a prick project directory"
|
323
335
|
File.directory?(SCHEMA_DIR) or Prick.error "Not in a prick project directory"
|
324
|
-
File.exist?(
|
336
|
+
File.exist?(project_path) or Prick.error "Can't find project file '#{project_path}'"
|
325
337
|
end
|
326
338
|
|
327
339
|
# Load state
|
328
|
-
state = Prick.state = State.new(
|
340
|
+
state = Prick.state = State.new(project_path, environment_path, reflections_file, state_path, fox_state_path)
|
329
341
|
|
330
342
|
# Lazyness
|
331
343
|
database = state.database
|
@@ -338,7 +350,7 @@ begin
|
|
338
350
|
|
339
351
|
when :setup!
|
340
352
|
clean_pg_meta_cache
|
341
|
-
state.project_loaded? or Prick.error "No #{
|
353
|
+
state.project_loaded? or Prick.error "No #{project_path} found"
|
342
354
|
username, database, environment = parse_database_args(state, args)
|
343
355
|
require_db(database, exist: false)
|
344
356
|
Prick::SubCommand.setup(database, username, environment)
|
data/lib/prick/constants.rb
CHANGED
@@ -10,7 +10,7 @@ module Prick
|
|
10
10
|
SHARE_PATH = "#{File.dirname(File.dirname(__dir__))}/lib/prick/share"
|
11
11
|
LIBEXEC_PATH = "#{File.dirname(File.dirname(__dir__))}/lib/prick/libexec"
|
12
12
|
|
13
|
-
# Project directories
|
13
|
+
# Project directories (relative to PRICK_DIR)
|
14
14
|
DIRS = [
|
15
15
|
MIGRATION_DIR = "migration",
|
16
16
|
SCHEMA_DIR = "schema",
|
@@ -26,33 +26,48 @@ module Prick
|
|
26
26
|
SPEC_DIR = "spec"
|
27
27
|
]
|
28
28
|
|
29
|
-
# Prick project root directory
|
30
|
-
PRICK_DIR = Dir.getwd
|
31
|
-
|
32
29
|
# Search path for executables
|
33
30
|
# PRICK_PATH = "#{ENV['PATH']}:#{PRICK_DIR}/#{BIN_DIR}:#{PRICK_DIR}/#{LIBEXEC_DIR}"
|
34
31
|
|
35
|
-
# Project
|
32
|
+
# Project filename
|
36
33
|
PRICK_PROJECT_FILE = "prick.yml"
|
37
|
-
|
34
|
+
|
35
|
+
# Project root directory. nil when running rspec
|
36
|
+
if !defined?(PRICK_DIR)
|
37
|
+
PRICK_DIR = begin
|
38
|
+
dir = Dir.getwd
|
39
|
+
while dir != "/" && !File.exist?("#{dir}/prick.yml")
|
40
|
+
dir = File.dirname(dir)
|
41
|
+
end
|
42
|
+
if dir == "/"
|
43
|
+
defined?(RSpec) or raise ArgumentError, "Can't find prick project directory"
|
44
|
+
dir = ""
|
45
|
+
end
|
46
|
+
dir
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Project file path
|
51
|
+
PRICK_PROJECT_PATH = File.join(PRICK_DIR, PRICK_PROJECT_FILE)
|
38
52
|
|
39
53
|
# Environment file
|
40
54
|
PRICK_ENVIRONMENT_FILE = "prick.environment.yml"
|
41
|
-
PRICK_ENVIRONMENT_PATH = PRICK_ENVIRONMENT_FILE
|
55
|
+
PRICK_ENVIRONMENT_PATH = File.join(PRICK_DIR, PRICK_ENVIRONMENT_FILE)
|
56
|
+
|
42
57
|
|
43
58
|
# TODO: Move to var/cache
|
44
59
|
|
45
60
|
# State file
|
46
61
|
PRICK_STATE_FILE = ".prick.state.yml"
|
47
|
-
PRICK_STATE_PATH = PRICK_STATE_FILE
|
62
|
+
PRICK_STATE_PATH = File.join(PRICK_DIR, PRICK_STATE_FILE)
|
48
63
|
|
49
64
|
# Fox state file (contains anchors and table sizes)
|
50
65
|
FOX_STATE_FILE = ".fox-state.yml"
|
51
|
-
FOX_STATE_PATH = FOX_STATE_FILE
|
66
|
+
FOX_STATE_PATH = File.join(PRICK_DIR, FOX_STATE_FILE)
|
52
67
|
|
53
68
|
# PgMeta snapshot. Is deleted at the start of each build
|
54
69
|
PG_META_STATE_FILE = ".pg_meta-state.yml"
|
55
|
-
PG_META_STATE_PATH = PG_META_STATE_FILE
|
70
|
+
PG_META_STATE_PATH = File.join(PRICK_DIR, PG_META_STATE_FILE)
|
56
71
|
|
57
72
|
# Reflections file
|
58
73
|
REFLECTIONS_FILE = "reflections.yml"
|
@@ -66,7 +81,6 @@ module Prick
|
|
66
81
|
SPEC_TMP_DIR = "spec"
|
67
82
|
SPEC_TMP_PATH = File.join(TMP_DIR, SPEC_TMP_DIR)
|
68
83
|
|
69
|
-
|
70
84
|
# Migration diff files
|
71
85
|
DIFF_FILE = "diff.sql"
|
72
86
|
DIFF_FILES = [
|
@@ -82,7 +96,7 @@ module Prick
|
|
82
96
|
|
83
97
|
# The project state file
|
84
98
|
PROJECT_STATE_FILE = ".prick-project"
|
85
|
-
PROJECT_STATE_PATH = PROJECT_STATE_FILE
|
99
|
+
PROJECT_STATE_PATH = File.join(PRICK_DIR, PROJECT_STATE_FILE)
|
86
100
|
|
87
101
|
# The the .prick-migration file
|
88
102
|
PRICK_MIGRATION_FILE = ".prick-migration"
|
data/lib/prick/state.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
require 'yaml'
|
3
|
+
require_relative './prick_version.rb'
|
3
4
|
|
4
5
|
module Prick
|
5
6
|
# There is only one State object: Prick.state
|
@@ -317,10 +318,8 @@ module Prick
|
|
317
318
|
}
|
318
319
|
end
|
319
320
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
def read_yaml(file)
|
321
|
+
# To give lib/prick.rb access
|
322
|
+
def self.read_yaml(file)
|
324
323
|
begin
|
325
324
|
YAML.load File.read(file).sub(/^__END__\n.*/m, "")
|
326
325
|
rescue Errno::ENOENT
|
@@ -328,7 +327,8 @@ module Prick
|
|
328
327
|
end
|
329
328
|
end
|
330
329
|
|
331
|
-
|
330
|
+
# To give lib/prick.rb access
|
331
|
+
def self.load_yaml(file, mandatory_keys, optional_keys = [])
|
332
332
|
mandatory_keys = mandatory_keys.map(&:to_s)
|
333
333
|
optional_keys = optional_keys.map(&:to_s)
|
334
334
|
hash = read_yaml(file) or Prick.error "Not a valid YAML file - #{file}"
|
@@ -340,6 +340,15 @@ module Prick
|
|
340
340
|
hash
|
341
341
|
end
|
342
342
|
|
343
|
+
private
|
344
|
+
# YAML helper methods
|
345
|
+
|
346
|
+
def read_yaml(file) self.class.read_yaml(file) end
|
347
|
+
|
348
|
+
def load_yaml(file, mandatory_keys, optional_keys = [])
|
349
|
+
self.class.load_yaml(file, mandatory_keys, optional_keys)
|
350
|
+
end
|
351
|
+
|
343
352
|
def save_yaml(file, hash)
|
344
353
|
self.class.save_yaml(file, hash)
|
345
354
|
end
|
data/lib/prick/version.rb
CHANGED
data/lib/prick-command.rb
CHANGED
data/lib/prick.rb
CHANGED
@@ -1,17 +1,11 @@
|
|
1
1
|
|
2
2
|
require 'pg_conn'
|
3
|
+
require 'yaml'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
while dir != "/" && !File.exist?("#{dir}/prick.yml")
|
7
|
-
dir = File.dirname(dir)
|
8
|
-
end
|
5
|
+
require_relative 'prick/constants.rb'
|
6
|
+
require_relative 'prick/state.rb'
|
9
7
|
|
10
|
-
|
11
|
-
defined?(RSpec) or raise ArgumentError, "Can't find prick project directory"
|
12
|
-
else
|
13
|
-
$LOAD_PATH.unshift("#{dir}/lib")
|
14
|
-
end
|
8
|
+
$LOAD_PATH.unshift(File.join Prick::PRICK_DIR, "lib")
|
15
9
|
|
16
10
|
# Create a new database connection or an existing connection. The connection
|
17
11
|
# exists when the script is run by prick as a subprocess using fork
|
@@ -19,9 +13,14 @@ module Prick
|
|
19
13
|
def self.conn(database, username = nil)
|
20
14
|
if self.respond_to?(:owner_conn)
|
21
15
|
self.owner_conn
|
22
|
-
|
23
|
-
!database.nil? or raise ArgumentError, "No database given"
|
16
|
+
elsif database
|
24
17
|
PgConn.new(database, username || database)
|
18
|
+
elsif File.exist?(Prick::PRICK_STATE_PATH)
|
19
|
+
hash = State.load_yaml(Prick::PRICK_STATE_PATH, %w(database username), %w(environment))
|
20
|
+
PgConn.new(hash["database"], hash["username"])
|
21
|
+
else
|
22
|
+
raise ArgumentError, "No database given"
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
26
|
+
|