pre-commit 0.9.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pre-commit/checks/migration_check.rb +22 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d14a6ce5ee2717ae7d88d9fb68b80dbfd6380e1
|
4
|
+
data.tar.gz: 1358302054df917ca046543c2cb075c81323e0ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67c1e0fa3d6aa160683efe67aa0cc1f9540a73a284d1cc2dd5454ad45b1f4bb79e327c34e008fb92096edae4f4382a45a1d09ed862c000dc3d644e84c6717b02
|
7
|
+
data.tar.gz: 72d69a94f724d062ac47ee938e531e34c7d5f38b73ec900cb0846392e4536f3303000c5f06730bf941f918a8f517000070b17d30e5ca4f2e67ab3171aefbfd3a
|
@@ -1,27 +1,32 @@
|
|
1
1
|
module PreCommit
|
2
2
|
class MigrationCheck
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
class << self
|
4
|
+
def call(staged_files)
|
5
|
+
migration_files = migration_files(staged_files)
|
6
|
+
schema_files = schema_files(staged_files)
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
if migration_files.any? && schema_files.none?
|
9
|
+
"It looks like you're adding a migration, but did not update the schema file"
|
10
|
+
elsif migration_files.none? && schema_files.any?
|
11
|
+
"You're trying to change the schema without adding a migration file"
|
12
|
+
elsif migration_files.any? && schema_files.any?
|
13
|
+
versions = migration_files.map { |f| f[/\d+/] }
|
14
|
+
schema = schema_files.map { |f| File.read(f) }.join
|
15
|
+
missing_versions = versions.select { |version| !schema.include?(version) }
|
16
|
+
if missing_versions.any?
|
17
|
+
"You did not add the schema versions for #{versions.join(', ')} to #{schema_files.join(' or ')}"
|
18
|
+
end
|
19
|
+
end
|
11
20
|
end
|
12
|
-
end
|
13
21
|
|
14
|
-
|
15
|
-
staged_files.any? { |file| file =~ /db\/migrate\/.*\.rb/ }
|
16
|
-
end
|
22
|
+
private
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
def migration_files(staged_files)
|
25
|
+
staged_files.grep(/db\/migrate\/.*\.rb/)
|
26
|
+
end
|
21
27
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
28
|
+
def schema_files(staged_files)
|
29
|
+
staged_files.select { |f| File.basename(f) =~ /schema\.rb|structure.*\.sql/ }
|
25
30
|
end
|
26
31
|
end
|
27
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pre-commit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shajith Chacko, Josh Lubaway
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: execjs
|