prick 0.39.12 → 0.39.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ebdfba60b4161b0afa671e4c19abf963db5d017376c089acade485e5d895dc8
4
- data.tar.gz: a3cff45e06c66cb094fa3ca891b4d3a863d21ab52f2fb13ff1b9c2d026bb494b
3
+ metadata.gz: 7e4a3abb3d16add6ac8a34d01cf1b4f8c47db59b97110d5a53f7c137d7fac786
4
+ data.tar.gz: 197a7fed189ac1ace4fb185d17287aa397ab207c4b6c4def6e929341968ea5f3
5
5
  SHA512:
6
- metadata.gz: 16a1deeabd509f289eeb1fff91a2880e21794bd1124862b84f0fd9c4cad19c512d22d2733ac9cd7b9bf0b288f536739cd9b1c1da88b002f1e2c4ceb9dd2c677a
7
- data.tar.gz: 477ce9af0329c7b07a89be381f73cf47629f97b38395342dc817b0ccc051b20b1381da92e6bd71ed9cebb0f8a0b6e9a559eeaf7944b980f1c215d440f0d56f6f
6
+ metadata.gz: fabd3040287e7db1deace3ec62929eac32535a2182963fcf1842c868f56e8b25d3e0fbd8c0d93cfd6f1bfd7eaa970c9a3532c89aec3ae90611b703b677c5738f
7
+ data.tar.gz: 1a0dda8115fcd8f0d2aa100257782f50e7e2f2bd04c9fca7d20d64900e59623faf7a3f607ccd2c3b79bdfab50d1d9f251dc4abc770bef42523d82a626d88e980
data/TODO CHANGED
@@ -1,3 +1,4 @@
1
+ o Make references to file stable when using -C
1
2
  o prefix sql scripts with 'set ON_ERROR_STOP on'
2
3
  o make it possible to build only one scheme
3
4
  o cleanup connection
@@ -11,7 +12,7 @@ o Have the following entries
11
12
  sql: SQL_STATEMENT
12
13
  exec: BASH_COMMAND
13
14
  eval: BASH_COMMAND
14
- call:
15
+ call:
15
16
  ...
16
17
 
17
18
 
data/exe/prick CHANGED
@@ -37,9 +37,15 @@ SPEC = %(
37
37
  -e,environment-file=ENVIRONMENT-FILE
38
38
  Override the environment file. Default is 'prick.environment.yml'
39
39
 
40
+ -r,reflections-file=REFLECTIONS-FILE
41
+ Override the reflections file. Default is 'schema/reflections.yml'
42
+
40
43
  -s,state-file=STATE-FILE
41
44
  Override state file. Default is '.prick-state.yml'
42
45
 
46
+ -f,fox-state-file=FOX-STATE-FILE
47
+ Override fox state file. Default is '.fox-state.yml
48
+
43
49
  init! -n,name=NAME -t,title=TITLE DIRECTORY #@ Initialize new Prick project directory
44
50
  Initializes a prick project and checks it into git. If a directory is
45
51
  given the directory will be created and the project initialized in it.
@@ -117,7 +123,9 @@ SPEC = %(
117
123
  drop.data!
118
124
  @ Drop data
119
125
 
120
- TODO
126
+ Drop data added to the database after the last snapshot was taken. It is
127
+ useful to run 'prick snapshot' immediately after you complete building
128
+ the database
121
129
 
122
130
  build! --step -f,force -t,time --dump=KIND? -- [SCHEMA]
123
131
  Build the project. If SCHEMA is defined, later schemas are excluded. KIND
@@ -134,12 +142,15 @@ SPEC = %(
134
142
  run! --step -t,time --dump=KIND? --schema=SCHEMA -- PATH
135
143
  @ Execute path in Prick environment
136
144
 
137
- Execute a single directory or file within the Prick environment. If given
138
- a directory argument, the directory is searched for a build.yml file. If
139
- given a file argument, the file should be a .sql, .fox, or build file
145
+ Execute a single build directory or file within the Prick environment. If
146
+ given a directory argument, the directory is searched for a build.yml
147
+ file. If given a file argument, the file should be a .sql, .fox, or build
148
+ file
140
149
 
141
150
  The --schema option sets the current schema before executing the PATH
142
151
 
152
+ TODO: Allow executables
153
+
143
154
  touch! -- [SUCCESS]
144
155
  Record a build. SUCCESS can be 'true' (default) or 'false'. 'touch' is
145
156
  used by external build processes that doesn't involve prick
@@ -148,18 +159,19 @@ SPEC = %(
148
159
  Emit a bash script to build the database. The script is constructed from
149
160
  the build attributes in the environment file
150
161
 
151
- fox! -- FILE...
152
- Load fox file data. Data are reset to their initial state after build
153
- before the fox data are loaded. This makes it possible to experiment with
154
- different data sets
162
+ fox! -r,reset +e,exclude=SCHEMA... -- FILE...
163
+ Load fox file data. Can be used together with 'prick snapshot' and 'prick
164
+ drop data' to to experiment with different data sets
155
165
 
156
- # TODO: A --clean option that resets data
157
- #
166
+ The --reset option resets data to the last snapshot before loading the
167
+ file. The --exclude option lists schemas that should not be included in
168
+ fox, typically schemas that doens't comply with prick's naming
169
+ conventions
158
170
 
159
171
  snapshot!
160
- Records maximum ID for all tables and stores them in prick.snapshot. It is
161
- used by 'drop data' to reset data to the point in time of the snapshot.
162
- Only one snapshot can be created at a time
172
+ Records maximum ID for all tables and stores them in the prick.snapshot
173
+ table. It is used by 'drop data' to reset data to the point in time of
174
+ the snapshot. Only one snapshot can be created at a time
163
175
 
164
176
  reset!
165
177
  Restore database to the last snapshot. TODO
@@ -240,6 +252,10 @@ def clean_pg_meta_cache
240
252
  FileUtils.rm_f(PG_META_STATE_PATH)
241
253
  end
242
254
 
255
+ def clean_fox_state
256
+ FileUtils.rm_f(Prick.state.fox_state_file)
257
+ end
258
+
243
259
  def parse_database_args(state, args)
244
260
  arg, environment = args.expect(0..2)
245
261
  if arg
@@ -287,7 +303,9 @@ begin
287
303
  # Handle -p, -e, and -c. TODO: Take -C into account for relative paths. Low-hanging fruit
288
304
  project_file = opts.project_file || PRICK_PROJECT_PATH
289
305
  environment_file = opts.environment_file || PRICK_ENVIRONMENT_PATH
306
+ reflections_file = opts.reflections_file || REFLECTIONS_PATH
290
307
  state_file = opts.state_file || PRICK_STATE_PATH
308
+ fox_state_file = opts.fox_state_file || FOX_STATE_PATH
291
309
 
292
310
  # Process init command and exit
293
311
  if opts.subcommand == :init!
@@ -307,7 +325,7 @@ begin
307
325
  end
308
326
 
309
327
  # Load state
310
- state = Prick.state = State.new(project_file, environment_file, state_file)
328
+ state = Prick.state = State.new(project_file, environment_file, reflections_file, state_file, fox_state_file)
311
329
 
312
330
  # Lazyness
313
331
  database = state.database
@@ -381,6 +399,7 @@ begin
381
399
  when :build!
382
400
  require_db
383
401
  clean_pg_meta_cache
402
+ clean_fox_state
384
403
  dump = cmd.dump? ? cmd.dump("batches")&.to_sym || :batches : nil
385
404
  # exclude = cmd.exclude? ? cmd.exclude.split(",") : []
386
405
  Prick::SubCommand.build(
@@ -390,6 +409,7 @@ begin
390
409
  when :make!
391
410
  require_db
392
411
  clean_pg_meta_cache
412
+ clean_fox_state
393
413
  dump = cmd.dump? ? cmd.dump("batches")&.to_sym || :batches : nil
394
414
  Prick::SubCommand.make(
395
415
  database, username, args.expect(0..1),
@@ -415,7 +435,7 @@ begin
415
435
 
416
436
  when :fox!
417
437
  require_db
418
- Prick::SubCommand.fox(database, username, args)
438
+ Prick::SubCommand.fox(database, username, args, reset: cmd.reset?, exclude: cmd.exclude)
419
439
 
420
440
  when :snapshot!
421
441
  require_db
@@ -122,8 +122,12 @@ module Prick
122
122
  t_type.stop
123
123
  t_fox = Timer.new " Parse files"
124
124
 
125
+ # Fetch state
126
+ ids, anchors = FixtureFox::Fox.read_state(type, Prick.state.fox_state_file)
127
+
125
128
  # Create fox object
126
- fox = FixtureFox::Fox.new(type)
129
+ #
130
+ fox = FixtureFox::Fox.new(type, ids: ids, anchors: anchors)
127
131
 
128
132
  # Parse files
129
133
  for file in files
@@ -135,8 +139,8 @@ module Prick
135
139
  fox.assign_types
136
140
  fox.generate
137
141
 
138
- # Dump state file
139
- fox.write_state(FOX_STATE_PATH)
142
+ # Dump new state file
143
+ fox.write_state(Prick.state.fox_state_file)
140
144
 
141
145
  # Timer
142
146
  t_fox.stop
@@ -66,7 +66,7 @@ module Prick
66
66
 
67
67
  @conn = conn
68
68
  @path = path
69
- @reflections_file = REFLECTIONS_PATH
69
+ @reflections_file = Prick.state.reflections_file
70
70
  @clean = clean
71
71
  @single = single
72
72
  @step = step
data/lib/prick/state.rb CHANGED
@@ -24,9 +24,16 @@ module Prick
24
24
  # absent if the project doesn't use environments
25
25
  attr_reader :environment_file
26
26
 
27
+ # Reflections file. Default 'schema/reflections.yml'. May be nil if the
28
+ # file is absent
29
+ attr_reader :reflections_file
30
+
27
31
  # State file. Default '.prick-state.yml'
28
32
  attr_reader :state_file
29
33
 
34
+ # Fox state file. Default '.fox-state.yml'
35
+ attr_reader :fox_state_file
36
+
30
37
  # Schema data file. FIXME What is this?
31
38
  def schema_file() SCHEMA_VERSION_PATH end
32
39
 
@@ -95,8 +102,9 @@ module Prick
95
102
  @clean = Git.clean?
96
103
  end
97
104
 
98
- def initialize(project_file, environment_file, state_file)
99
- @project_file, @environment_file, @state_file = project_file, environment_file, state_file
105
+ def initialize(project_file, environment_file, reflections_file, state_file, fox_state_file)
106
+ @project_file, @environment_file, @reflections_file, @state_file, @fox_state_file =
107
+ project_file, environment_file, reflections_file, state_file, fox_state_file
100
108
  @project_loaded = @state_loaded = @environment_loaded = false
101
109
 
102
110
  if @project_file && File.exist?(@project_file)
@@ -3,8 +3,16 @@
3
3
  require_relative '../builder/builder.rb'
4
4
 
5
5
  module Prick::SubCommand
6
- def self.fox(database, username, files)
7
- Command.command "fox --state=#{FOX_STATE_PATH} --exec #{database} #{files.join(" ")}"
6
+ def self.fox(database, username, files, reset: false, exclude: nil)
7
+ self.drop_data(database) # In prick-drop
8
+ opts = {
9
+ state: FOX_STATE_PATH,
10
+ delete: "none",
11
+ exec: true,
12
+ exclude: (exclude ? exclude.join(',') : nil),
13
+ reflections: Prick.state.reflections_file
14
+ }.reject { |k,v| v.nil? }.map { |k,v| "--#{k}#{v == true ? "" : "=#{v}"}" }.join(" ")
15
+ Command.command "fox #{opts} #{database} #{files.join(" ")}"
8
16
  end
9
17
  end
10
18
 
@@ -31,7 +31,7 @@ module Prick::SubCommand
31
31
  Command.status == 0 or Prick.failure "Failed creating initial import"
32
32
 
33
33
  # Write (valid) configuration file
34
- state = State.new(project_file, nil, nil)
34
+ state = State.new(project_file, nil, nil, nil, nil)
35
35
  state.name = name
36
36
  state.title = title
37
37
  state.prick_version = PrickVersion.new VERSION
@@ -4,7 +4,7 @@ require_relative '../builder/builder.rb'
4
4
 
5
5
  module Prick::SubCommand
6
6
  def self.snapshot(
7
- database, username,
7
+ database, username,
8
8
  builddir: Prick.state.schema_dir)
9
9
 
10
10
  conn = Prick.state.connection
@@ -24,6 +24,13 @@ module Prick::SubCommand
24
24
  }
25
25
  end
26
26
  conn.insert("prick", "snapshots", records)
27
+
28
+ # Patch fox state file
29
+ state = YAML.load(IO.read(Prick.state.fox_state_file))
30
+ for record in records
31
+ state[:ids][record[:schema_name] + '.' + record[:table_name]] = record[:max_id] if record[:max_id]
32
+ end
33
+ IO.write(Prick.state.fox_state_file, YAML.dump(state))
27
34
  end
28
35
  end
29
36
 
data/lib/prick/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Prick
4
- VERSION = "0.39.12"
4
+ VERSION = "0.39.13"
5
5
  end
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.39.12
4
+ version: 0.39.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-09 00:00:00.000000000 Z
11
+ date: 2024-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semantic