pg_spec_helper 1.8.3 → 1.8.5
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 +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/pg_spec_helper/columns.rb +1 -1
- data/lib/pg_spec_helper/foreign_keys.rb +5 -5
- data/lib/pg_spec_helper/functions.rb +1 -3
- data/lib/pg_spec_helper/indexes.rb +1 -1
- data/lib/pg_spec_helper/materialized_views.rb +1 -1
- data/lib/pg_spec_helper/primary_keys.rb +2 -2
- data/lib/pg_spec_helper/schemas.rb +1 -1
- data/lib/pg_spec_helper/tables.rb +2 -2
- data/lib/pg_spec_helper/version.rb +1 -1
- data/lib/pg_spec_helper.rb +0 -2
- metadata +2 -3
- data/lib/pg_spec_helper/sanitize.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80425037527e477dc7bbb76dbeba05d0a9339f6cf829ee1f9d17338c99bb3e95
|
4
|
+
data.tar.gz: b7a29ce7a34962211ce7100330754b9d10dc53c0910efd5d987c776b9ca9e819
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a47cc3dc6c0744df722e420af888ffb552b6df4aeb44caeef0e8d5c6a8f25e4ec2218ac6f537caca7d23d891e09631aa8951b57934b5bea070a8535b21d22807
|
7
|
+
data.tar.gz: d255fd2adaffd140017ff8c8a8961e1251782b6bee1773ebaee283e86be75a5acbd70c5df5aa87a9f236266b34f9cffc331e07e0581958c62d4918e1f47d83f0
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [1.8.5](https://github.com/craigulliott/pg_spec_helper/compare/v1.8.4...v1.8.5) (2023-08-19)
|
4
|
+
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
|
8
|
+
* removing the sanitization of sql data (it is useless in this gem, and gets in the way of testing some things, which defeats the point of this gem) ([fe6af3b](https://github.com/craigulliott/pg_spec_helper/commit/fe6af3bd4443b140a3136d43f1da61315de4d761))
|
9
|
+
|
10
|
+
## [1.8.4](https://github.com/craigulliott/pg_spec_helper/compare/v1.8.3...v1.8.4) (2023-08-18)
|
11
|
+
|
12
|
+
|
13
|
+
### Bug Fixes
|
14
|
+
|
15
|
+
* function definitions no longer presume/add their own BEGIN and END, which now allows providing custom SQL such as DEFINE statements ([2ec7d00](https://github.com/craigulliott/pg_spec_helper/commit/2ec7d00bd2ad539860384981586b0bcee98d56a7))
|
16
|
+
|
3
17
|
## [1.8.3](https://github.com/craigulliott/pg_spec_helper/compare/v1.8.2...v1.8.3) (2023-08-06)
|
4
18
|
|
5
19
|
|
@@ -10,7 +10,7 @@ class PGSpecHelper
|
|
10
10
|
# note the `type` is safe from sql_injection due to the validation above
|
11
11
|
connection.exec(<<~SQL)
|
12
12
|
ALTER TABLE #{connection.quote_ident schema_name.to_s}.#{connection.quote_ident table_name.to_s}
|
13
|
-
ADD COLUMN #{connection.quote_ident column_name.to_s} #{
|
13
|
+
ADD COLUMN #{connection.quote_ident column_name.to_s} #{type} #{null ? "" : "NOT NULL"}
|
14
14
|
SQL
|
15
15
|
end
|
16
16
|
|
@@ -4,14 +4,14 @@ class PGSpecHelper
|
|
4
4
|
module ForeignKeys
|
5
5
|
# Create a foreign key
|
6
6
|
def create_foreign_key schema_name, table_name, column_names, foreign_schema_name, foreign_table_name, foreign_column_names, foreign_key_name
|
7
|
-
column_names_sql = column_names.
|
8
|
-
foreign_column_names_sql = foreign_column_names.
|
7
|
+
column_names_sql = column_names.join(", ")
|
8
|
+
foreign_column_names_sql = foreign_column_names.join(", ")
|
9
9
|
# add the foreign key
|
10
10
|
connection.exec(<<~SQL)
|
11
|
-
ALTER TABLE #{
|
12
|
-
ADD CONSTRAINT #{
|
11
|
+
ALTER TABLE #{schema_name}.#{table_name}
|
12
|
+
ADD CONSTRAINT #{foreign_key_name}
|
13
13
|
FOREIGN KEY (#{column_names_sql})
|
14
|
-
REFERENCES #{
|
14
|
+
REFERENCES #{foreign_schema_name}.#{foreign_table_name} (#{foreign_column_names_sql})
|
15
15
|
SQL
|
16
16
|
end
|
17
17
|
|
@@ -6,9 +6,7 @@ class PGSpecHelper
|
|
6
6
|
def create_function schema_name, function_name, function_definition
|
7
7
|
connection.exec <<~SQL
|
8
8
|
CREATE FUNCTION #{schema_name}.#{function_name}() returns trigger language plpgsql AS
|
9
|
-
|
10
|
-
RETURN NEW;
|
11
|
-
END$$;
|
9
|
+
$$#{function_definition.strip}$$;
|
12
10
|
SQL
|
13
11
|
end
|
14
12
|
|
@@ -4,7 +4,7 @@ class PGSpecHelper
|
|
4
4
|
module Indexes
|
5
5
|
# Create an index
|
6
6
|
def create_index schema_name, table_name, column_names, index_name
|
7
|
-
column_names_sql = column_names.
|
7
|
+
column_names_sql = column_names.join(", ")
|
8
8
|
connection.exec(<<~SQL)
|
9
9
|
CREATE INDEX #{connection.quote_ident index_name.to_s}
|
10
10
|
ON #{connection.quote_ident schema_name.to_s}.#{connection.quote_ident table_name.to_s} (#{column_names_sql})
|
@@ -71,7 +71,7 @@ class PGSpecHelper
|
|
71
71
|
# time the materialized view is found to exist, at which point the method
|
72
72
|
# will always return true
|
73
73
|
@materialized_views[schema_name.to_sym][materialized_view_name.to_sym][:exists] ||= connection.exec(<<~SQL).count > 0
|
74
|
-
SELECT TRUE AS exists FROM pg_matviews WHERE schemaname = '#{
|
74
|
+
SELECT TRUE AS exists FROM pg_matviews WHERE schemaname = '#{schema_name}' AND matviewname = '#{materialized_view_name}';
|
75
75
|
SQL
|
76
76
|
end
|
77
77
|
|
@@ -7,8 +7,8 @@ class PGSpecHelper
|
|
7
7
|
column_names_sql = column_names.map { |n| connection.quote_ident n.to_s }.join(", ")
|
8
8
|
# add the primary_key
|
9
9
|
connection.exec(<<~SQL)
|
10
|
-
ALTER TABLE #{
|
11
|
-
ADD CONSTRAINT #{
|
10
|
+
ALTER TABLE #{schema_name}.#{table_name}
|
11
|
+
ADD CONSTRAINT #{primary_key_name}
|
12
12
|
PRIMARY KEY (#{column_names_sql})
|
13
13
|
SQL
|
14
14
|
end
|
@@ -11,7 +11,7 @@ class PGSpecHelper
|
|
11
11
|
|
12
12
|
# return a list of the schema names in the database
|
13
13
|
def get_schema_names
|
14
|
-
ignored_schemas_sql = ignored_schemas.
|
14
|
+
ignored_schemas_sql = ignored_schemas.join("', '")
|
15
15
|
# return a list of the schema names from the database
|
16
16
|
results = connection.exec(<<~SQL)
|
17
17
|
SELECT schema_name
|
@@ -5,7 +5,7 @@ class PGSpecHelper
|
|
5
5
|
# create a new table in the provided schema
|
6
6
|
def create_table schema_name, table_name
|
7
7
|
connection.exec(<<~SQL)
|
8
|
-
CREATE TABLE #{
|
8
|
+
CREATE TABLE #{schema_name}.#{table_name}(
|
9
9
|
-- tables are created empty, and have columns added to them later
|
10
10
|
);
|
11
11
|
SQL
|
@@ -30,7 +30,7 @@ class PGSpecHelper
|
|
30
30
|
-- temporarily set the client_min_messages to WARNING to
|
31
31
|
-- suppress the NOTICE messages about cascading deletes
|
32
32
|
SET client_min_messages TO WARNING;
|
33
|
-
DROP TABLE #{
|
33
|
+
DROP TABLE #{schema_name}.#{table_name} CASCADE;
|
34
34
|
SET client_min_messages TO NOTICE;
|
35
35
|
SQL
|
36
36
|
end
|
data/lib/pg_spec_helper.rb
CHANGED
@@ -6,7 +6,6 @@ require "pg"
|
|
6
6
|
require "pg_spec_helper/version"
|
7
7
|
|
8
8
|
require "pg_spec_helper/connection"
|
9
|
-
require "pg_spec_helper/sanitize"
|
10
9
|
require "pg_spec_helper/ignored_schemas"
|
11
10
|
require "pg_spec_helper/schemas"
|
12
11
|
require "pg_spec_helper/tables"
|
@@ -31,7 +30,6 @@ class PGSpecHelper
|
|
31
30
|
end
|
32
31
|
|
33
32
|
include Connection
|
34
|
-
include Sanitize
|
35
33
|
include IgnoredSchemas
|
36
34
|
include Schemas
|
37
35
|
include Tables
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_spec_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Ulliott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -62,7 +62,6 @@ files:
|
|
62
62
|
- lib/pg_spec_helper/models.rb
|
63
63
|
- lib/pg_spec_helper/primary_keys.rb
|
64
64
|
- lib/pg_spec_helper/reset.rb
|
65
|
-
- lib/pg_spec_helper/sanitize.rb
|
66
65
|
- lib/pg_spec_helper/schemas.rb
|
67
66
|
- lib/pg_spec_helper/table_executer.rb
|
68
67
|
- lib/pg_spec_helper/tables.rb
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class PGSpecHelper
|
4
|
-
module Sanitize
|
5
|
-
class UnsafePostgresNameError < StandardError
|
6
|
-
end
|
7
|
-
|
8
|
-
# returns a sanitized version of the provided name, raises an error
|
9
|
-
# if it is not valid
|
10
|
-
#
|
11
|
-
# this is probably unnessesary due to this gem being used within a test
|
12
|
-
# suite and not a production application, but it is here for completeness
|
13
|
-
# and an abundance of caution
|
14
|
-
def sanitize_name name
|
15
|
-
# ensure the name is a string
|
16
|
-
name = name.to_s
|
17
|
-
# ensure the name is not empty
|
18
|
-
raise UnsafePostgresNameError, "name cannot be empty" if name.empty?
|
19
|
-
# ensure the name does not contain invalid characters
|
20
|
-
raise UnsafePostgresNameError, "name contains invalid characters" unless /\A[a-zA-Z0-9_-]+\z/.match?(name)
|
21
|
-
# return the name
|
22
|
-
name
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|