lexicon-common 0.2.0 → 0.2.1

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: 67f0a5454bbfd0be7a918086e92beb80d00adfbc5ad5e018619dc28198a9be39
4
- data.tar.gz: 63da11d671ced447b6c9f78acabdcdf0dbab6c620fc7f88b6e8e28ecd7ffeb36
3
+ metadata.gz: 5b24914e5f9dbd3d4261ec1b6c04741958a5d9fcfccb9dde8fd14b92b5c19b57
4
+ data.tar.gz: 7b2a40b0e4e033dbc111804a5c6a6a7105fdd2ac991d72baeb7022e66f585913
5
5
  SHA512:
6
- metadata.gz: b7e1f34a8a91a980156eaabe9456d0c08ddbac1cc4c231f73905dace76c40d095cccd158f8406f9f28e51b7ebb70c6d98b4c27a1dca2b4eacaa75f916b41145c
7
- data.tar.gz: 627de86d02381a2ec9ab550b4c384d7d084860c7c18ab7f0f9863cf928c5f6867e5e418183a06540bf75fca21dbd667c42e6cf97a9b4921e7300041f06f285ea
6
+ metadata.gz: 0b7e024f856d40571826aa8237cfbd0b1ea55be19bf31f997ce5f65cf04c561ffaa43d4b5c23b5fcdda05ae7f3b48629ae0ca68c0c91903fa362e4674e3cdbd4
7
+ data.tar.gz: 7c225eb0b67789074fa76e5a50bcc61439503b5fb579d811077732b7f9763efc822f7f4c12d2aa314d5b0719ef3820d0eff097e08aaa3c167d442f48665dbe64
@@ -50,7 +50,7 @@ module Lexicon
50
50
  drop_schema(schema, cascade: true)
51
51
  end
52
52
 
53
- def drop_schema(name, cascade: false)
53
+ def drop_schema(name, cascade: false, if_exists: false)
54
54
  cascade = if cascade
55
55
  ' CASCADE'
56
56
  else
@@ -58,7 +58,7 @@ module Lexicon
58
58
  end
59
59
 
60
60
  query <<~SQL
61
- DROP SCHEMA "#{name}"#{cascade};
61
+ DROP SCHEMA #{if_exists ? 'IF EXISTS ' : ''}"#{name}"#{cascade};
62
62
  SQL
63
63
  end
64
64
 
@@ -95,6 +95,28 @@ module Lexicon
95
95
  @connection.copy_data(sql) { block.call(put_data) }
96
96
  end
97
97
 
98
+ # @param [#to_s] table
99
+ # @param [#to_s | nil] schema
100
+ # @return [Boolean]
101
+ def table_exists?(table, schema: nil)
102
+ schema = search_path.first if schema.nil?
103
+
104
+ query(<<~SQL, table, schema).any?
105
+ SELECT table_name FROM information_schema.tables
106
+ WHERE table_name = $1 AND table_schema = $2
107
+ SQL
108
+ end
109
+
110
+ # @param [#to_s] schema_name
111
+ # @return [Boolean]
112
+ def schema_exists?(schema_name)
113
+ query(<<~SQL, schema_name).count > 0
114
+ SELECT "schema_name"
115
+ FROM "information_schema"."schemata"
116
+ WHERE "schema_name" = $1
117
+ SQL
118
+ end
119
+
98
120
  private
99
121
 
100
122
  # @return [PG::Connection]
@@ -153,7 +153,7 @@ module Lexicon
153
153
  # @param [String] schema
154
154
  def load_csv(file, into:, schema:)
155
155
  psql.execute_raw(<<~SQL)
156
- \\copy "#{schema}"."#{into}" FROM PROGRAM 'zcat #{file}' WITH csv
156
+ \\copy "#{schema}"."#{into}" FROM PROGRAM 'zcat < #{file}' WITH csv
157
157
  SQL
158
158
  end
159
159
 
@@ -1,5 +1,5 @@
1
1
  module Lexicon
2
2
  module Common
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.2.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lexicon-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ekylibre developers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-31 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3
@@ -178,7 +178,7 @@ dependencies:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
180
  version: 1.11.0
181
- description:
181
+ description:
182
182
  email:
183
183
  - dev@ekylibre.com
184
184
  executables: []
@@ -221,7 +221,7 @@ homepage: https://www.ekylibre.com
221
221
  licenses:
222
222
  - AGPL-3.0-only
223
223
  metadata: {}
224
- post_install_message:
224
+ post_install_message:
225
225
  rdoc_options: []
226
226
  require_paths:
227
227
  - lib
@@ -236,8 +236,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
236
  - !ruby/object:Gem::Version
237
237
  version: '0'
238
238
  requirements: []
239
- rubygems_version: 3.0.3
240
- signing_key:
239
+ rubygems_version: 3.4.7
240
+ signing_key:
241
241
  specification_version: 4
242
242
  summary: Common classes and services for Ekylibre's Lexicon
243
243
  test_files: []