tapsoob 0.5.18-java → 0.5.20-java

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: 264143377d615e0ea97a2a4662223fc092d596439e04d26dd4d55a6573f42376
4
- data.tar.gz: f529f8fc13c44d6fa58bbf93bc31024c25356ef24f2618ce9891d50e49849ddd
3
+ metadata.gz: c9da95cfa0ca6f5bba8840d86ceb8cb6f2476abd44274a900ae2076a4c2a83fe
4
+ data.tar.gz: '028c4375fd4efd418d248f53ef341ca6af15416fb4581302fc24e16fc654b27a'
5
5
  SHA512:
6
- metadata.gz: 945524a15035febcf6e8e29f4a158012128e7144cbfcd7d63207e9608554adf23989865f620932a1afc00e93db234be7108b8fdaa2bd08af71052bb1d80fb385
7
- data.tar.gz: b7351a86a5f4c3e37dc9751adb9c4c9e0cd2e52d4b0c53caa38b73e94e1e953bb5ab4921819940ca50a66d96f7d8529d7484aa986e3e948ed7dd9b239bae1e01
6
+ metadata.gz: 5c67b884c0a4814784f13730c8243212b618652a4c9ecb26170daf5e2f8196b473112c19ef1ed3635e7d918c7c6fe036b2ceb347a29c0f326104de09a6b51e37
7
+ data.tar.gz: d70869b92b6c1291e5c16138295c078c6d90369a4b916461e96bf382f581f8a46ed6026bc7f964827fec4f84baf7c7317482f955845c48ec7e2e05c0c73128e4
@@ -15,10 +15,12 @@ module Tapsoob
15
15
 
16
16
  desc "dump DATABASE_URL", "Dump a database using a database URL"
17
17
  option :indexes, type: :boolean, default: false
18
+ option :"foreign-keys", type: :boolean, default: false
18
19
  option :"same-db", type: :boolean, default: false
19
20
  def dump(database_url)
20
21
  opts = {}
21
22
  opts[:indexes] = options[:"indexes"]
23
+ opts[:foreign_keys] = options[:"foreign-keys"]
22
24
  opts[:same_db] = options[:"same-db"]
23
25
 
24
26
  puts Tapsoob::Schema.dump(database_url, opts)
@@ -29,6 +31,11 @@ module Tapsoob
29
31
  puts Tapsoob::Schema.dump_table(database_url, table)
30
32
  end
31
33
 
34
+ desc "foreign_keys DATABASE_URL", "Dump foreign_keys from a database using a database URL"
35
+ def foreign_keys(database_url)
36
+ puts Tapsoob::Schema.foreign_keys(database_url)
37
+ end
38
+
32
39
  desc "indexes DATABASE_URL", "Dump indexes from a database using a database URL"
33
40
  def indexes(database_url)
34
41
  puts Tapsoob::Schema.indexes(database_url)
@@ -44,7 +51,7 @@ module Tapsoob
44
51
  Tapsoob::Schema.reset_db_sequences(database_url)
45
52
  end
46
53
 
47
- desc "load DATABASE_URL [FILENAME]", "Load a database schema from a file to a database using a database URL"
54
+ desc "load DATABASE_URL [FILENAME]", "Load a database schema from a file or STDIN to a database using a database URL"
48
55
  option :drop, type: :boolean, default: false
49
56
  def load(database_url, filename = nil)
50
57
  schema = if filename && File.exists?(filename)
@@ -60,7 +67,22 @@ module Tapsoob
60
67
  end
61
68
  end
62
69
 
63
- desc "load_indexes DATABASE_URL [FILENAME]", "Load indexes from a file to a database using a database URL"
70
+ desc "load_foreign_keys DATABASE_URL [FILENAME]", "Load foreign keys from a file or STDIN to a database using a database URL"
71
+ def load_foreign_keys(database_url, filename = nil)
72
+ indexes = if filename && File.exists?(filename)
73
+ File.read(filename)
74
+ else
75
+ STDIN.read
76
+ end
77
+
78
+ begin
79
+ Tapsoob::Schema.load_foreign_keys(database_url, indexes)
80
+ rescue Exception => e
81
+ throw e
82
+ end
83
+ end
84
+
85
+ desc "load_indexes DATABASE_URL [FILENAME]", "Load indexes from a file or STDIN to a database using a database URL"
64
86
  def load_indexes(database_url, filename = nil)
65
87
  indexes = if filename && File.exists?(filename)
66
88
  File.read(filename)
@@ -49,6 +49,12 @@ END_MIG
49
49
  end
50
50
  end
51
51
 
52
+ def foreign_keys(database_url)
53
+ db = Sequel.connect(database_url)
54
+ db.extension :schema_dumper
55
+ db.dump_foreign_key_migration
56
+ end
57
+
52
58
  def indexes(database_url)
53
59
  db = Sequel.connect(database_url)
54
60
  db.extension :schema_dumper
@@ -98,6 +104,13 @@ END_MIG
98
104
  end
99
105
  end
100
106
 
107
+ def load_foreign_keys(database_url, foreign_keys)
108
+ Sequel.connect(database_url) do |db|
109
+ db.extension :schema_dumper
110
+ eval(foreign_keys).apply(db, :up)
111
+ end
112
+ end
113
+
101
114
  def load_indexes(database_url, indexes)
102
115
  Sequel.connect(database_url) do |db|
103
116
  db.extension :schema_dumper
data/lib/tapsoob/utils.rb CHANGED
@@ -77,14 +77,14 @@ Data : #{data}
77
77
  # Add types if schema isn't empty
78
78
  db.extension :schema_dumper # Add schema dumper extension in case it hasn't been added until now
79
79
  res[:types] = schema.map do |c|
80
- case db.column_schema_to_ruby_type(c.last)[:type]
81
- when BigDecimal
80
+ case db.column_schema_to_ruby_type(c.last)[:type].to_s
81
+ when "BigDecimal"
82
82
  "float"
83
- when :Bignum
83
+ when "Bignum"
84
84
  "integer"
85
- when File
85
+ when "File"
86
86
  "blob"
87
- when TrueClass
87
+ when "TrueClass"
88
88
  "boolean"
89
89
  else
90
90
  db.column_schema_to_ruby_type(c.last)[:type].to_s.downcase
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Tapsoob
3
- VERSION = "0.5.18".freeze
3
+ VERSION = "0.5.20".freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapsoob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.18
4
+ version: 0.5.20
5
5
  platform: java
6
6
  authors:
7
7
  - Félix Bellanger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-02-13 00:00:00.000000000 Z
12
+ date: 2023-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: !ruby/object:Gem::Requirement