wowsql-sdk 3.0.1 → 3.0.2
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/lib/wowsql/schema.rb +20 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 826f10bf64044521d6fdd2688f0f77b57924660eaff0f8df2658d337da7fc1ca
|
|
4
|
+
data.tar.gz: aaf8344c9fdd01c54c96c3ebe7deb8d3d2e35f246135cd9e73edc89f3c64f241
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a82163cee9e520989407d4c69ec4f5bf8b27c9ca74a661f804bb74f2e85fa8227c0d3bb2cd7409c2900d33afb93b5f127958381f1894ec312ac5b60dad8abe54
|
|
7
|
+
data.tar.gz: 8be9c1806765790513bc99d7fd6cdcb9484de4fd5e767b1f7de01369406da10b85a291c4009252fbe7247d6172b08a86b4e89a1ea474acc6652d1dc829f66176
|
data/lib/wowsql/schema.rb
CHANGED
|
@@ -13,7 +13,7 @@ module WOWSQL
|
|
|
13
13
|
# "wowsql_service_..."
|
|
14
14
|
# )
|
|
15
15
|
# schema.create_table("users", [
|
|
16
|
-
# { "name" => "id", "type" => "
|
|
16
|
+
# { "name" => "id", "type" => "UUID", "auto_increment" => true },
|
|
17
17
|
# { "name" => "email", "type" => "VARCHAR(255)", "unique" => true, "nullable" => false },
|
|
18
18
|
# { "name" => "name", "type" => "VARCHAR(255)" },
|
|
19
19
|
# { "name" => "metadata", "type" => "JSONB", "default" => "'{}'" },
|
|
@@ -64,10 +64,14 @@ module WOWSQL
|
|
|
64
64
|
#
|
|
65
65
|
# @param table_name [String] Name of the table
|
|
66
66
|
# @param columns [Array<Hash>] Column definitions (name, type, auto_increment, unique, nullable, default)
|
|
67
|
-
# @param primary_key [String
|
|
67
|
+
# @param primary_key [String] Primary key column name (must be the UUID column)
|
|
68
68
|
# @param indexes [Array<String>, nil] Columns to create indexes on
|
|
69
69
|
# @return [Hash]
|
|
70
|
-
def create_table(table_name, columns, primary_key
|
|
70
|
+
def create_table(table_name, columns, primary_key:, indexes: nil)
|
|
71
|
+
raise ArgumentError, 'primary_key is required; primary key must be UUID type.' if primary_key.nil? || primary_key.to_s.strip.empty?
|
|
72
|
+
|
|
73
|
+
assert_uuid_primary_key!(primary_key, columns)
|
|
74
|
+
|
|
71
75
|
request('POST', '/api/v2/schema/tables', nil, {
|
|
72
76
|
table_name: table_name,
|
|
73
77
|
columns: columns,
|
|
@@ -76,6 +80,19 @@ module WOWSQL
|
|
|
76
80
|
})
|
|
77
81
|
end
|
|
78
82
|
|
|
83
|
+
private
|
|
84
|
+
|
|
85
|
+
def assert_uuid_primary_key!(primary_key, columns)
|
|
86
|
+
col = columns.find { |c| c['name'] == primary_key || c[:name] == primary_key }
|
|
87
|
+
raise ArgumentError, 'Primary key column not found in columns.' unless col
|
|
88
|
+
|
|
89
|
+
type_str = (col['type'] || col[:type]).to_s
|
|
90
|
+
first = type_str.strip.split(/\s+/, 2).first.to_s.upcase
|
|
91
|
+
raise ArgumentError, 'Primary key column must use PostgreSQL type UUID.' unless first == 'UUID'
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
public
|
|
95
|
+
|
|
79
96
|
# Alter an existing table.
|
|
80
97
|
#
|
|
81
98
|
# Operations: add_column, drop_column, modify_column, rename_column
|