prick 0.44.0 → 0.45.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e046355817f1eaf7637ad6738524e25988e26bb29cfbd5e78078cb2d30e71dc3
4
- data.tar.gz: 1d0afc75efbafd486f3242b6adaa3d61ff245482facb936de29032ac87d053b5
3
+ metadata.gz: 939683467498ed042cfb77197ecb0edab5c0a63ad24f2e2686ac2b6a86f9b010
4
+ data.tar.gz: 75e47615dbe7dc04531c629bcbc6db9ec91631e98fbbeee8f5ad31f6b3d0e612
5
5
  SHA512:
6
- metadata.gz: e2431481ad1746d8657b3d569e7ce75f3b00d2109639d06aa8ce3a572e5d5994b69a5325214530ec8f8ba5559baef16b5731a91ae16528ba8fa4745ced92d092
7
- data.tar.gz: c69e5435b07a36a766213a22b158655310479edaa5f7e934bb019e5d0d91c62458f2f8d7c03557747057fd1f892a972a990a26267e489722d60a33d3767e05c7
6
+ metadata.gz: d07ee1e9a1cc5a5c5c10c4af753a5ca2d2831588f4df377dacd33d27346928b536f90eb03037f68f2c9497ac5dcdab369deb10a3aa36125a0415a6520cfeeb51
7
+ data.tar.gz: e2a670c6d6fac252e4505884243bca0eff469044bb6e10548c2a17bc82235785ad507db07325eab8d0b16d0ccbd1eb50146dabe110669540ca9aac174d2c9415
data/exe/prick CHANGED
@@ -51,8 +51,12 @@ SPEC = %(
51
51
  given the directory will be created and the project initialized in it.
52
52
  Default name and title is derived from the directory name
53
53
 
54
- setup! -- [OWNER@]DATABASE [ENVIRONMENT] @ Create and set current database
55
- Create database and owner and set the current database
54
+ Note that no files are copied currently :-O
55
+
56
+ setup! --prick -- [OWNER@]DATABASE [ENVIRONMENT] @ Create and set current database
57
+ Create database and owner and set the current database. The --prick
58
+ option creates the database or clears an existing database before
59
+ rebuilding the prick schema. It is used to update the prick schema
56
60
 
57
61
  teardown! -- [DATABASE...] @ Remove database and owner
58
62
  Drop database, database users, and database owner if possible and not the
@@ -91,6 +95,9 @@ SPEC = %(
91
95
  that you can have multiple databases and switch between them using the
92
96
  'set database' subcommand
93
97
 
98
+ create.prick! -- (Re-)initialize the prick schema
99
+ Create the prick schema. The database and owner are created if needed
100
+
94
101
  create.migration! -f,force -o,file=FILE -- VERSION @ Create migration
95
102
  Create a migration from VERSION to the current and write it to
96
103
  migration/VERSION. Fails if migration exist unless the --force flag is
@@ -233,8 +240,10 @@ SPEC = %(
233
240
  def require_db(database = Prick.state&.database, exist: true)
234
241
  database or raise ArgumentError
235
242
  dba = State.connection
243
+
236
244
  if exist
237
245
  dba.rdbms.exist?(database) or Prick.error "Can't find database '#{database}'"
246
+
238
247
  if Prick.state&.connection&.name == database
239
248
  close_conn = false
240
249
  conn = Prick.state.conn
@@ -267,7 +276,7 @@ def parse_database_args(state, args)
267
276
  username = database
268
277
  end
269
278
  else
270
- database = state.name
279
+ database = state.database
271
280
  username = database
272
281
  end
273
282
  database or Prick.error "Database is undefined"
@@ -394,6 +403,15 @@ begin
394
403
  database, username, environment = parse_database_args(state, args)
395
404
  require_db(database, exist: false)
396
405
  Prick::SubCommand.create_database(database, username, environment)
406
+ when :prick!
407
+ clean_pg_meta_cache
408
+ database, username, environment = parse_database_args(state, args)
409
+ if Prick::SubCommand.exist_database?(database)
410
+ Prick::SubCommand.clean(database, exclude: [])
411
+ Prick::SubCommand.init_database(database, username, environment)
412
+ else
413
+ Prick::SubCommand.create_database(database, username, environment)
414
+ end
397
415
  when :migration!
398
416
  # clean_pg_meta_cache # FIXME ?
399
417
  require_db
@@ -403,10 +421,10 @@ begin
403
421
  username, version,
404
422
  force: create_command.subcommand!.force?,
405
423
  file: create_command.subcommand!.file)
406
- when :users, :schema, :data, :all
424
+ when :users!, :schema!, :data!, :all!
407
425
  raise NotImplementedError
408
426
  else
409
- raise ArgumentError
427
+ raise ArgumentError, "Unexpected subcommand #{create_command.subcommand.inspect}"
410
428
  end
411
429
 
412
430
  when :build!
@@ -5,7 +5,8 @@
5
5
  # environment just to create the prick schema. After the initial setup, the
6
6
  # scripts are only run by 'prick build' with the --force option
7
7
  #
8
- # This is hardcoded an should be fixed somehow
8
+ # Note that the content of this file is hardcoded in
9
+ # lib/prick/subcommand/prick-create.rb. This is a bug FIXME
9
10
  #
10
11
  ---
11
12
  - schema: prick
@@ -0,0 +1,15 @@
1
+ -- Controlled by prick(1). Don't touch
2
+ --
3
+
4
+ create function prick.version() returns text as $$
5
+ select version from prick.versions;
6
+ $$ language sql;
7
+
8
+ create function prick.success() returns boolean as $$
9
+ select coalesce(success, false) from prick.versions;
10
+ $$ language sql;
11
+
12
+ create function prick.built_at() returns timestamp as $$
13
+ select coalesce(built_at, '1970-01-01 00:00:00'::timestamp from prick.versions;
14
+ $$ language sql;
15
+
@@ -41,8 +41,10 @@ module Prick::SubCommand
41
41
 
42
42
  # Drop all schemas except the prick schema and re-creates the
43
43
  # public schema
44
- builder.pool.delete_schema("prick") if super_conn.schema.exist?("prick")
45
- super_conn.rdbms.empty!(database, public: false, exclude: ["prick"])
44
+ # builder.pool.delete_schema("prick") if super_conn.schema.exist?("prick")
45
+ # super_conn.rdbms.empty!(database, public: false, exclude: ["prick"])
46
+ super_conn.rdbms.empty!(database, public: false)
47
+ Prick::SubCommand::init_database(database, username)
46
48
  else
47
49
  # Find all schemas
48
50
  refresh_schemas = conn.schema.list
@@ -6,10 +6,10 @@ module Prick::SubCommand
6
6
  # Drop users and hollow-out database. This has the same as effect as
7
7
  # teardown+setup but without recreating the database owner and the database
8
8
  # which would otherwise terminate all user sessions
9
- def self.clean(database)
10
- drop_users(database)
9
+ def self.clean(database, exclude: %w(prick))
10
+ Prick::SubCommand.drop_users(database)
11
11
  State.connection { |conn|
12
- conn.rdbms.empty!(database, exclude: ["prick"]) if conn.rdbms.exist?(database)
12
+ conn.rdbms.empty!(database, exclude: exclude) if conn.rdbms.exist?(database)
13
13
  }
14
14
  end
15
15
  end
@@ -1,6 +1,10 @@
1
1
  module Prick
2
2
  module SubCommand
3
- PRICK_BUILD_FILES = %w(tables.sql views.sql) # HARDCODED
3
+ PRICK_BUILD_FILES = %w(tables.sql views.sql functions.sql) # FIXME FIXME FIXME HARDCODED
4
+
5
+ def self.exist_database?(database)
6
+ State.connection.rdbms.exist? database
7
+ end
4
8
 
5
9
  def self.create_database(database, username, environment)
6
10
  super_conn = State.connection
@@ -16,6 +20,13 @@ module Prick
16
20
  # Create database
17
21
  super_conn.rdbms.create database, owner: username
18
22
 
23
+ # Initialize prick schema
24
+ init_database database, username, environment
25
+ end
26
+
27
+ # Setup prick schema. Used when we rebuild the prick schema without
28
+ # disconnecting users
29
+ def self.init_database(database, username, environment)
19
30
  # Setup Prick schema. Note that this is hardcoded, the prick build file
20
31
  # is ignored
21
32
  conn = PgConn.new(database, username) # Can't use Prick.state.connection on a new database
@@ -27,6 +27,7 @@ module Prick::SubCommand
27
27
  else
28
28
  conn.rdbms.role.drop(users)
29
29
  end
30
+
30
31
  else
31
32
  # We don't terminate sessions because we assume one-database-users
32
33
  # FIXME: users is undefined
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.44.0"
4
+ VERSION = "0.45.1"
5
5
  end
data/lib/prick-command.rb CHANGED
@@ -84,7 +84,6 @@ module Prick
84
84
  from information_schema.tables
85
85
  where table_schema = 'prick'
86
86
  and table_name = 'builds'
87
- limit 1
88
87
  ))
89
88
  yield(database, conn) if is_prick_database && block_given?
90
89
  is_prick_database
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.44.0
4
+ version: 0.45.1
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-11-17 00:00:00.000000000 Z
11
+ date: 2024-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semantic
@@ -223,6 +223,7 @@ files:
223
223
  - lib/prick/share/init/schema/build.yml
224
224
  - lib/prick/share/init/schema/prick/.keep
225
225
  - lib/prick/share/init/schema/prick/build.yml
226
+ - lib/prick/share/init/schema/prick/functions.sql
226
227
  - lib/prick/share/init/schema/prick/tables.sql
227
228
  - lib/prick/share/init/schema/prick/views.sql
228
229
  - lib/prick/share/init/schema/public/.keep