prick 0.6.0 → 0.11.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: d1acbb39706f5c58e4ef47230fa18cea7fb16d3c15c3fdc500624b859b4328bc
4
- data.tar.gz: 9853c05b7f3717d0c12e68595f0dd945d95d84f372b7d438efe222ba2388e62a
3
+ metadata.gz: 2788abf0737d8f89b08f4dcbe8cf026ffb4927a2a155655b28350c53951c2c1f
4
+ data.tar.gz: a336758b7ff556e11346f7bb0f6da9e949a2d51b7f4f377b24d9e91d0b92af50
5
5
  SHA512:
6
- metadata.gz: f3ad4787717d1f9c3a1eb6d727dbfd9b5a22b0a13c22951d25a757ead4bae71831ba35d26dc2dbec5b68d826c3469c44eded315dade0de4f6819e6c4193a7389
7
- data.tar.gz: a630950080794df280914d7980095827010ae717ea14262a4dc4a95b25af2fbbb50a4116d52fb912461a1a03aa9be910ad6a115857ba5fbe70cb20b1d977aa87
6
+ metadata.gz: e8352c55f6fd37f84c4495f8c1ffe89b5594f936fe74d500e77fe44a7c5fe367c7995dd6824a446c67c36891af892bc277c4c757fe5e6c60a4b07b12e8698809
7
+ data.tar.gz: 25e407b34434192eb797cb83bd265b6b2b7004341dee7ba7ab8b64582d9730d2a5ea19dacde7eaa9474d2c2f7e96559a0fbdf4d9fb9fc1e07c8ac9fb6a0c55e6
data/exe/prick CHANGED
@@ -251,7 +251,7 @@ begin
251
251
  program.save(version, file)
252
252
 
253
253
  when :drop
254
- program.drop(args.expect(0..1), opts.drop!.all)
254
+ program.drop(args.expect(0..1), opts.drop!.all?)
255
255
 
256
256
  when :diff
257
257
  mark = opts.diff!.mark
data/lib/prick.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- $LOAD_PATH.unshift("/home/clr/prj/shellopts/lib")
2
+ #$LOAD_PATH.unshift("/home/clr/prj/shellopts/lib")
3
3
 
4
4
  # 'semantic' is required here instead of in prick/version.rb to avoid having Gem depend on it
5
5
  require "semantic"
data/lib/prick/builder.rb CHANGED
@@ -7,18 +7,24 @@ module Prick
7
7
  # and is used to match a build file. Build files are looked up in the
8
8
  # following order:
9
9
  #
10
- # #{name}, #{name}.* executable
10
+ # #{name} executable
11
+ # #{name}.* executable
11
12
  # #{name}.yml
12
13
  # #{name}.sql
13
14
  # #{name}/
14
15
  #
16
+ # The output from executable objects is expected to be SQL statements that
17
+ # are fed into postgres
18
+ #
15
19
  # When a resource match a directory, the directory can contain a special
16
20
  # default resource ('build' or 'migrate') that takes over the rest of the
17
21
  # build process for that directory. Typically, you'll use the 'build.yml' or
18
- # 'migrate.yml' to control the build order of the other resources
22
+ # 'migrate.yml' to control the build order of the other resources If a
23
+ # directory doesn't contain a build resource, the resources in the directory
24
+ # are built in alphabetic order
19
25
  #
20
- # If a directory doesn't contain a build resource, the resources in the
21
- # directory are built in alphabetic order
26
+ # Build (but not migration) SQL scripts and executables are executed with
27
+ # search path set to containing schema
22
28
  #
23
29
  class Builder
24
30
  attr_reader :database
@@ -57,11 +63,11 @@ module Prick
57
63
  Dir.chdir(dir) { yield(file) }
58
64
  end
59
65
 
60
- def do_sql(path)
66
+ def do_sql(path, schema: nil)
61
67
  # puts "do_sql(#{path})"
62
68
  do_dir(path) { |file|
63
69
  if @execute
64
- Rdbms.exec_file(database.name, file, user: database.user)
70
+ Rdbms.exec_file(database.name, file, user: database.user, schema: schema)
65
71
  else
66
72
  @lines += IO.readlines(file).map(&:chomp)
67
73
  end
@@ -69,12 +75,12 @@ module Prick
69
75
  true
70
76
  end
71
77
 
72
- def do_exe(path)
78
+ def do_exe(path, schema: nil)
73
79
  # puts "do_exe(#{path})"
74
80
  do_dir(path) { |file|
75
81
  lines = Command.command "#{file} #{database.name} #{database.user}" # FIXME Security
76
82
  if @execute
77
- Rdbms.exec_sql(database.name, lines.join("\n"), database.user)
83
+ Rdbms.exec_sql(database.name, lines.join("\n"), user: database.user, schema: schema)
78
84
  else
79
85
  @lines += lines
80
86
  end
@@ -159,6 +165,17 @@ module Prick
159
165
  end
160
166
 
161
167
  def self.yml_file(directory) File.join(directory, "build") + ".yml" end
168
+
169
+ protected
170
+ def do_sql(path)
171
+ schema = Dir.getwd.sub(/^.*schema\/([^\/]+)(?:\/.*)?$/, '\1')
172
+ super(path, schema: schema)
173
+ end
174
+
175
+ def do_exe(path)
176
+ schema = Dir.getwd.sub(/^.*schema\/([^\/]+)(?:\/.*)?$/, '\1')
177
+ super(path, schema: schema)
178
+ end
162
179
  end
163
180
  end
164
181
 
@@ -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
@@ -151,7 +151,7 @@ module Prick
151
151
 
152
152
  def prepare_release(fork)
153
153
  project.prepare_release(fork)
154
- enda
154
+ end
155
155
 
156
156
  def prepare_feature(name)
157
157
  raise NotYet
@@ -162,7 +162,7 @@ module Prick
162
162
  end
163
163
 
164
164
  def prepare_schema(name)
165
- raise NotYet
165
+ project.prepare_schema(name)
166
166
  end
167
167
 
168
168
  def prepare_diff(version = nil)
data/lib/prick/project.rb CHANGED
@@ -162,6 +162,16 @@ module Prick
162
162
  self
163
163
  end
164
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
+
165
175
  def prepare_diff(from_version = version)
166
176
  begin
167
177
  from_name = "#{name}-base"
data/lib/prick/rdbms.rb CHANGED
@@ -1,20 +1,18 @@
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
9
  # Execute the SQL statement and return stdout as an array of tuples
13
- def self.exec_sql(db, sql, user: ENV['USER'])
10
+ def self.exec_sql(db, sql, user: ENV['USER'], schema: nil)
11
+ schema ||= "public"
14
12
  stdout = Command.command %(
15
13
  {
16
14
  echo "set role #{user};"
17
- echo "set search_path to public;"
15
+ echo "set search_path to #{schema};"
18
16
  cat <<'EOF'
19
17
  #{sql}
20
18
  EOF
@@ -24,8 +22,8 @@ EOF
24
22
  end
25
23
 
26
24
  # Execute the given file and return stdout as an array of tuples
27
- def self.exec_file(db, file, user: ENV['USER'])
28
- 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)
29
27
  end
30
28
 
31
29
  # Execute the SQL statement and return the result as an array of record tuples
@@ -133,16 +131,6 @@ EOF
133
131
  data_opt = (data ? "" : "--schema-only")
134
132
  Command.command "pg_dump --no-owner #{data_opt} #{db} | gzip --to-stdout >#{file}"
135
133
  end
136
-
137
- private
138
- @ensure_states = {
139
- exist_user: [:create_user, :drop_user],
140
- exist_database: [
141
- lambda { |this, db, user| this.ensure_state(:exist_user, user) },
142
- lambda { |this, db, user| this.create_database(db, owner: user) },
143
- :drop_database
144
- ]
145
- }
146
134
  end
147
135
  end
148
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.6.0"
7
+ VERSION = "0.11.0"
8
8
  end
9
9
 
10
10
  # Project related code starts here
@@ -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.6.0
4
+ version: 0.11.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-02-10 00:00:00.000000000 Z
11
+ date: 2021-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shellopts
@@ -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
@@ -1,3 +0,0 @@
1
- set search_path to public;
2
-
3
-