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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/wowsql/schema.rb +20 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b1d25a46f571516a8f5caf131a4f4c08a0abc65096d31b6aa0327d4d655e5f6
4
- data.tar.gz: 8556ffdf57f567ec79ff3fa9301636408fa85e253fa789089e0bfdf7b839892f
3
+ metadata.gz: 826f10bf64044521d6fdd2688f0f77b57924660eaff0f8df2658d337da7fc1ca
4
+ data.tar.gz: aaf8344c9fdd01c54c96c3ebe7deb8d3d2e35f246135cd9e73edc89f3c64f241
5
5
  SHA512:
6
- metadata.gz: '0260624397edc0928794c4d33a5a582c35a07f6cc9cc959a59f7877d91c04cf26756c6f71b83d25f34111adce9956433bf472abb6e65776464a6c05a14253c26'
7
- data.tar.gz: 074df084c7999068cece3c4f9f056e5df83ee31fcbd6b2efd217149574c04061b92de2ec0a7bda65635121d3252824a32f07913ee326fcbb06c7dc55a2351066
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" => "SERIAL", "auto_increment" => true },
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, nil] Primary key column name
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: nil, indexes: nil)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wowsql-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - WOWSQL Team