prick 0.44.0 → 0.45.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 +23 -5
- data/lib/prick/share/init/schema/prick/build.yml +2 -1
- data/lib/prick/share/init/schema/prick/functions.sql +15 -0
- data/lib/prick/subcommand/prick-build.rb +4 -2
- data/lib/prick/subcommand/prick-clean.rb +3 -3
- data/lib/prick/subcommand/prick-create.rb +12 -1
- data/lib/prick/subcommand/prick-drop.rb +1 -0
- data/lib/prick/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50679c9e2d6caab8f9301842615f9efa4f68ccc4521dfb5b62f5f3197d5ab54f
|
4
|
+
data.tar.gz: 18246ecf368dc70dbff3bcd317639a54d34b5416f900663cb93cf4cacf0d12af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 579cc06cb631d7bb3630f765b3d738daee63e2095a47a572a0babe04f75fe200d9cad19d1462ae0ea03b51dedbf0b24e659454c2706f2726f775b1ce12bced9a
|
7
|
+
data.tar.gz: bc636949f676bb2398c5feecd819f6c4974b98c14ffb502fab7617f8523c9502d400c0ac7d01182fb3839f583ff1c2b6952f6334674a29b18999ee4db602a2c7
|
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
|
-
|
55
|
-
|
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.
|
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
|
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
|
-
#
|
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
|
-
|
45
|
-
|
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:
|
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
|
data/lib/prick/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.45.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
@@ -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
|