database_schema_ownership 1.0.0 → 1.1.0

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: b5e756e987e34d6afc6217586393241faf93bf362adf8dac06ddcda94ac20b85
4
- data.tar.gz: 57a76af1486dcb2e317451be4f7ba9be6d940ab0ec1a23d471181041ce0698ad
3
+ metadata.gz: 5396c3f3e2e39ddc79d8e4e5a31880d4ffa9fbfefb93da3493c897a7a9e434ea
4
+ data.tar.gz: 19f66c853bb18fa2a1c67da7754f269b17ab0e7dd85543e9cb11780650d29e9b
5
5
  SHA512:
6
- metadata.gz: 1939d8886af6269f2ee40d1ceb10c5c0e10652fe44a308a62eb8b55be227727fdb45701251b77918eb554a13d8c23319bc557e61d37db152341c821ba4131b7c
7
- data.tar.gz: 39a9a193151dd8f4213af72870aa133058ee75dcb960850a8adf7826d9f71332da4362a73693d6cccb8e453887dcfbc84eb593631f75ad16fc68dd1c176872a6
6
+ metadata.gz: 941285797e42b66d24ea170b6af988d9de79ee6e67679134040f613c783d3c63248506cec4cfb0a7424dd23d5e907adaf88d94e4757c88377ea75212c79c1cb5
7
+ data.tar.gz: b40c68e71e934c1110aa4126f36ba59a6d2aadee3c9a847d3ffa21018de38bf413cdce3c1329565fc2e2459d2a2f17bc58156541ec4251e6817933b0f470e6fd
@@ -3,20 +3,11 @@
3
3
  module DatabaseSchemaOwnership
4
4
  class Parser
5
5
  class RubyParser < Parser # :nodoc:
6
- def parse
7
- parse_tables + parse_foreign_keys
8
- end
9
-
10
- def parse_tables
11
- schema.scan(/\n*(\s+create_table "([^"]*)".*?end)/m).map do |s|
12
- DatabaseSchemaOwnership::Entity.new(s[1], s[0])
13
- end
14
- end
15
-
16
- def parse_foreign_keys
17
- schema.scan(/\n*(\s+add_foreign_key "([^"]*)", "([^"]*)")/).map do |s|
18
- DatabaseSchemaOwnership::Entity.new(s[1], s[0])
19
- end
6
+ def rules
7
+ [
8
+ /\n*(\s+create_table "([^"]*)".*?end)/m,
9
+ /\n*(\s+add_foreign_key "([^"]*)", "([^"]*)")/
10
+ ]
20
11
  end
21
12
  end
22
13
  end
@@ -3,20 +3,18 @@
3
3
  module DatabaseSchemaOwnership
4
4
  class Parser
5
5
  class SqlParser < Parser # :nodoc:
6
- def parse
7
- parse_tables + parse_indexes
8
- end
9
-
10
- def parse_tables
11
- schema.scan(/(CREATE TABLE IF NOT EXISTS "([^"]*)"[^;]*;)/m).map do |s|
12
- DatabaseSchemaOwnership::Entity.new(s[1], s[0])
13
- end
14
- end
6
+ def rules
7
+ [
8
+ # ActiveRecord 8
9
+ /(CREATE TABLE IF NOT EXISTS "([^"]*)"[^;]*;)/m,
10
+ /(CREATE INDEX .* ON "([^"]*)"[^;]*;)/,
15
11
 
16
- def parse_indexes
17
- schema.scan(/(CREATE INDEX .* ON "([^"]*)"[^;]*;)/).map do |s|
18
- DatabaseSchemaOwnership::Entity.new(s[1], s[0])
19
- end
12
+ # early versions
13
+ /(CREATE TABLE (\S+) \([^;]*;)/m,
14
+ /(CREATE INDEX \S+ ON (\S+) USING [^;]*;)/,
15
+ /(CREATE UNIQUE INDEX \S+ ON (\S+) USING [^;]*;)/,
16
+ /(ALTER TABLE ONLY (\S+)[^;]*;)/m
17
+ ]
20
18
  end
21
19
  end
22
20
  end
@@ -18,7 +18,15 @@ module DatabaseSchemaOwnership
18
18
  end
19
19
 
20
20
  def schema
21
- File.read(schema_path)
21
+ @schema ||= File.read(schema_path)
22
+ end
23
+
24
+ def parse
25
+ rules.flat_map do |rule|
26
+ schema.scan(rule).map do |s|
27
+ DatabaseSchemaOwnership::Entity.new(s[1], "#{s[0]}\n")
28
+ end
29
+ end
22
30
  end
23
31
  end
24
32
  end
@@ -32,7 +32,7 @@ module DatabaseSchemaOwnership
32
32
  def group_entities(entities)
33
33
  entities.each_with_object({}) do |entity, hash|
34
34
  if hash[entity.name]
35
- hash[entity.name] += "\n#{entity.metadata}"
35
+ hash[entity.name] += entity.metadata
36
36
  else
37
37
  hash[entity.name] = entity.metadata
38
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DatabaseSchemaOwnership
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_schema_ownership
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Demin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-13 00:00:00.000000000 Z
11
+ date: 2024-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord