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 +4 -4
- data/lib/database_schema_ownership/parser/ruby_parser.rb +5 -14
- data/lib/database_schema_ownership/parser/sql_parser.rb +11 -13
- data/lib/database_schema_ownership/parser.rb +9 -1
- data/lib/database_schema_ownership/runner.rb +1 -1
- data/lib/database_schema_ownership/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5396c3f3e2e39ddc79d8e4e5a31880d4ffa9fbfefb93da3493c897a7a9e434ea
|
4
|
+
data.tar.gz: 19f66c853bb18fa2a1c67da7754f269b17ab0e7dd85543e9cb11780650d29e9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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] +=
|
35
|
+
hash[entity.name] += entity.metadata
|
36
36
|
else
|
37
37
|
hash[entity.name] = entity.metadata
|
38
38
|
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.
|
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-
|
11
|
+
date: 2024-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|