redmine_plugins_helper 0.11.0 → 0.12.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: 8232f2f6acdd4cc560ceb9f17d16f4b0cebb755b1ba35f5d5a49cd047c79c122
4
- data.tar.gz: 45b070c864548814a8a5da84c74b077104740afc3c5fffb94c74f39ffb626c0b
3
+ metadata.gz: 85bd7c23357b00ffca2152a68dadbc9419883bd1aa6e492f0a930aa9d8ddaa7c
4
+ data.tar.gz: 8b1674506dec4c5fa5746cd97688605885844bd755902b727cac593e3643f46d
5
5
  SHA512:
6
- metadata.gz: 510ad331ed7b3d416333afc33255e16a8cbb95708fdfa1cd95205e7d780dfe0670b0117bfa15d412c17493b74f7c7ee717c79eeeb9644a97e6b77b00a36781f5
7
- data.tar.gz: 1d44cd0abc79c8dcf6218c0cff87dffd5fc4d201d63a85d959e83a0c4803cf44ecaaab5c05e29ef379da36dafdfc6076f4dc63defe241120c5085039f9916563
6
+ metadata.gz: 1ad5db26a659560f2d424baccdd909b8aad0b3ea5ef9635bd1b983b2e584322506252999d9bf198e8cab19c063794117c9c62d4a3dbec8c71d32a4e7ad091550
7
+ data.tar.gz: fcd2784212814f604140e735068ba3b7feed262d8538a78cde6692d078e34c24119ed72f468c010c5bd14240abdabe59e2673fb3a85f1b110e912b4f1f362c77
data/lib/enumerator.rb ADDED
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ # Required by "sass/utils", it fails if RUBY_VERSION == 2.7.6.
@@ -11,6 +11,10 @@ module RedminePluginsHelper
11
11
  true
12
12
  end
13
13
 
14
+ def database_schema?
15
+ database? && ::RedminePluginsHelper::Migration.from_code.all?(&:applied?)
16
+ end
17
+
14
18
  def model?(*model_classes)
15
19
  table?(*model_classes.map(&:table_name))
16
20
  end
@@ -54,7 +54,7 @@ module RedminePluginsHelper
54
54
  end
55
55
 
56
56
  def local_versions
57
- @local_versions = begin
57
+ @local_versions ||= begin
58
58
  r = {}
59
59
  Redmine::Plugin.registered_plugins.each_value do |p|
60
60
  p.migrations.each do |m|
@@ -67,22 +67,8 @@ module RedminePluginsHelper
67
67
  end
68
68
 
69
69
  def database_plugins_versions
70
- @database_plugins_versions = begin
71
- r = []
72
- ::RedminePluginsHelper::Migrations.db_all_versions.each do |v|
73
- pv = parse_plugin_version(v)
74
- next unless pv
75
-
76
- r << pv
77
- end
78
- r
79
- end
80
- end
81
-
82
- def parse_plugin_version(version)
83
- h = ::RedminePluginsHelper::Migrations.parse_plugin_version(version)
84
- h[:version] = version if h.is_a?(Hash)
85
- h
70
+ @database_plugins_versions ||= ::RedminePluginsHelper::Migration
71
+ .from_database.select(&:plugin?).map(&:version)
86
72
  end
87
73
 
88
74
  def plugin_version(plugin_id, timestamp)
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedminePluginsHelper
4
+ class Migration
5
+ module Code
6
+ common_concern
7
+
8
+ module ClassMethods
9
+ # @return [Enumerable<RedminePluginsHelper::Migration>]
10
+ def from_code
11
+ from_core_code + from_plugins_code
12
+ end
13
+
14
+ # @return [Enumerable<RedminePluginsHelper::Migration>]
15
+ def from_core_code
16
+ ::Rails.application.paths['db/migrate'].flat_map do |path|
17
+ from_path_code(path)
18
+ end
19
+ end
20
+
21
+ # @return [Enumerable<RedminePluginsHelper::Migration>]
22
+ def from_path_code(path)
23
+ ::Dir["#{path}/*.rb"].map { |p| File.basename(p).match(/0*(\d+)\_/)[1].to_i }.sort
24
+ .map { |version| new(PLUGIN_ID_CORE_VALUE, version) }
25
+ end
26
+
27
+ # @return [Enumerable<RedminePluginsHelper::Migration>]
28
+ def from_plugins_code
29
+ ::Redmine::Plugin.registered_plugins.values.flat_map do |plugin|
30
+ plugin.migrations.map { |version| new(plugin.id, version) }
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedminePluginsHelper
4
+ class Migration
5
+ module Database
6
+ common_concern
7
+
8
+ DATABASE_CORE_VERSION_PARSER = /^(\d+)$/.to_parser { |m| [PLUGIN_ID_CORE_VALUE, m[1]] }
9
+ DATABASE_PLUGIN_VERSION_PARSER = /^(\d+)\-(\S+)$/.to_parser { |m| [m[2], m[1]] }
10
+ DATABASE_VERSION_PARSERS = [DATABASE_PLUGIN_VERSION_PARSER, DATABASE_CORE_VERSION_PARSER]
11
+ .freeze
12
+
13
+ module ClassMethods
14
+ # @return [Enumerable<RedminePluginsHelper::Migration>]
15
+ def from_database
16
+ ::ActiveRecord::SchemaMigration.create_table
17
+ ::ActiveRecord::SchemaMigration.all.pluck(:version).map do |version|
18
+ from_database_version(version)
19
+ end
20
+ end
21
+
22
+ # @return [RedminePluginsHelper::Migration]
23
+ def from_database_version(version)
24
+ DATABASE_VERSION_PARSERS
25
+ .lazy
26
+ .map { |parser| parser.parse(version).if_present { |args| new(*args) } }
27
+ .find(&:present?) || raise("None parser parsed \"#{version}\"")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedminePluginsHelper
4
+ class Migration
5
+ require_sub __FILE__, include_modules: true
6
+
7
+ PLUGIN_ID_CORE_VALUE = :_core_
8
+
9
+ common_constructor :plugin_id, :version do
10
+ self.plugin_id = plugin_id.to_sym
11
+ self.version = version.to_i
12
+ end
13
+
14
+ # @return [Boolean]
15
+ def applied?
16
+ ::ActiveRecord::SchemaMigration.create_table
17
+ ::ActiveRecord::SchemaMigration.where(version: database_version).any?
18
+ end
19
+
20
+ # @return [String]
21
+ def database_version
22
+ core? ? version.to_s : "#{version}-#{plugin_id}"
23
+ end
24
+
25
+ # @return [Boolean]
26
+ def core?
27
+ plugin_id == PLUGIN_ID_CORE_VALUE
28
+ end
29
+
30
+ # @return [Boolean]
31
+ def plugin?
32
+ !core?
33
+ end
34
+ end
35
+ end
@@ -5,38 +5,21 @@ module RedminePluginsHelper
5
5
  class << self
6
6
  def local_versions
7
7
  r = {}
8
- Redmine::Plugin.registered_plugins.each_value do |p|
9
- p.migrations.each do |ts|
10
- r[p.id] ||= []
11
- r[p.id] << ts
12
- end
8
+ ::RedminePluginsHelper::Migration.from_code.select(&:plugin?).each do |migration|
9
+ r[migration.plugin_id] ||= []
10
+ r[migration.plugin_id] << migration.version
13
11
  end
14
12
  r
15
13
  end
16
14
 
17
15
  def db_versions
18
16
  r = {}
19
- db_all_versions.each do |v|
20
- pv = parse_plugin_version(v)
21
- next unless pv
22
-
23
- r[pv[:plugin]] ||= []
24
- r[pv[:plugin]] << pv[:timestamp]
17
+ ::RedminePluginsHelper::Migration.from_database.select(&:plugin?).each do |migration|
18
+ r[migration.plugin_id] ||= []
19
+ r[migration.plugin_id] << migration.version
25
20
  end
26
21
  r
27
22
  end
28
-
29
- def db_all_versions
30
- ::ActiveRecord::SchemaMigration.create_table
31
- ::ActiveRecord::SchemaMigration.all.pluck(:version)
32
- end
33
-
34
- def parse_plugin_version(version)
35
- m = version.match(/^(\d+)\-(\S+)$/)
36
- return nil unless m
37
-
38
- { plugin: m[2].to_sym, timestamp: m[1].to_i }
39
- end
40
23
  end
41
24
  end
42
25
  end
@@ -3,5 +3,5 @@
3
3
  module RedminePluginsHelper
4
4
  AUTHOR = 'Eduardo Henrique Bogoni'
5
5
  SUMMARY = 'Helper for Redmine plugins'
6
- VERSION = '0.11.0'
6
+ VERSION = '0.12.0'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_plugins_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
- - 0.11.0
7
+ - 0.12.0
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-07 00:00:00.000000000 Z
11
+ date: 2022-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bigdecimal
@@ -111,11 +111,15 @@ files:
111
111
  - config/initializers/assets.rb
112
112
  - config/initializers/backport_pg_10_support_to_rails_4.rb
113
113
  - init.rb
114
+ - lib/enumerator.rb
114
115
  - lib/redmine_plugins_helper.rb
115
116
  - lib/redmine_plugins_helper/available.rb
116
117
  - lib/redmine_plugins_helper/fix_migrations.rb
117
118
  - lib/redmine_plugins_helper/hooks/add_assets.rb
118
119
  - lib/redmine_plugins_helper/migrate.rb
120
+ - lib/redmine_plugins_helper/migration.rb
121
+ - lib/redmine_plugins_helper/migration/code.rb
122
+ - lib/redmine_plugins_helper/migration/database.rb
119
123
  - lib/redmine_plugins_helper/migrations.rb
120
124
  - lib/redmine_plugins_helper/patches/redmine/plugin_migration_context.rb
121
125
  - lib/redmine_plugins_helper/patches/redmine/plugin_patch.rb