dsu 3.0.0.alpha.12 → 3.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/CHANGELOG.md +2 -0
  4. data/Gemfile +5 -5
  5. data/Gemfile.lock +19 -16
  6. data/lib/dsu/cli.rb +2 -1
  7. data/lib/dsu/crud/json_file.rb +5 -0
  8. data/lib/dsu/migration/base_service.rb +118 -0
  9. data/lib/dsu/migration/migrator.rb +24 -0
  10. data/lib/dsu/migration/raw_helpers/color_theme_hash.rb +13 -0
  11. data/lib/dsu/migration/raw_helpers/configuration_hash.rb +15 -0
  12. data/lib/dsu/migration/raw_helpers/entry_group_hash.rb +13 -0
  13. data/lib/dsu/migration/raw_json_file.rb +15 -0
  14. data/lib/dsu/migration/raw_json_files.rb +56 -0
  15. data/lib/dsu/migration/v20230613121411/service.rb +94 -0
  16. data/lib/dsu/migration/v20240210161248/service.rb +148 -0
  17. data/lib/dsu/models/color_theme.rb +2 -0
  18. data/lib/dsu/models/configuration.rb +6 -0
  19. data/lib/dsu/models/project.rb +2 -2
  20. data/lib/dsu/presenters/project/defaultable.rb +15 -0
  21. data/lib/dsu/presenters/project/use_by_number_presenter.rb +4 -0
  22. data/lib/dsu/presenters/project/use_presenter.rb +4 -0
  23. data/lib/dsu/subcommands/project.rb +3 -6
  24. data/lib/dsu/support/fileable.rb +11 -7
  25. data/lib/dsu/support/project_file_system.rb +2 -5
  26. data/lib/dsu/version.rb +2 -2
  27. data/lib/dsu/views/project/list.rb +4 -4
  28. data/lib/dsu.rb +8 -13
  29. data/lib/locales/en/commands.yml +4 -0
  30. data/lib/locales/en/miscellaneous.yml +1 -2
  31. data/lib/locales/en/subcommands.yml +21 -11
  32. data/lib/seed_data/20230613121411/dsu/migration_version.json +3 -0
  33. data/lib/seed_data/{themes → 20230613121411/dsu/themes}/light.json +2 -2
  34. data/lib/seed_data/20240210161248/dsu/current_project.json +4 -0
  35. data/lib/seed_data/20240210161248/dsu/migration_version.json +3 -0
  36. data/lib/seed_data/20240210161248/dsu/projects/default/project.json +5 -0
  37. data/lib/seed_data/20240210161248/dsu/themes/cherry.json +79 -0
  38. data/lib/seed_data/20240210161248/dsu/themes/christmas.json +79 -0
  39. data/lib/seed_data/20240210161248/dsu/themes/default.json +79 -0
  40. data/lib/seed_data/20240210161248/dsu/themes/lemon.json +79 -0
  41. data/lib/seed_data/20240210161248/dsu/themes/light.json +79 -0
  42. data/lib/seed_data/20240210161248/dsu/themes/matrix.json +79 -0
  43. data/lib/seed_data/20240210161248/dsu/themes/whiteout.json +79 -0
  44. metadata +32 -12
  45. data/lib/dsu/migration/factory.rb +0 -26
  46. data/lib/dsu/migration/service.rb +0 -196
  47. data/lib/dsu/migration/service_20230613121411.rb +0 -178
  48. /data/lib/seed_data/{themes → 20230613121411/dsu/themes}/cherry.json +0 -0
  49. /data/lib/seed_data/{themes → 20230613121411/dsu/themes}/christmas.json +0 -0
  50. /data/lib/seed_data/{themes → 20230613121411/dsu/themes}/default.json +0 -0
  51. /data/lib/seed_data/{themes → 20230613121411/dsu/themes}/lemon.json +0 -0
  52. /data/lib/seed_data/{themes → 20230613121411/dsu/themes}/matrix.json +0 -0
  53. /data/lib/seed_data/{themes → 20230613121411/dsu/themes}/whiteout.json +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74b0eee10983a1ccd33981f635c7bc267dd8db84cfe8496c39fa5386c57096d2
4
- data.tar.gz: f65368dfbb2de3512a73f766f82958de92255e4a72b3e5f58389d0db2ccd86ad
3
+ metadata.gz: a4e9cb8f6a8eb3af6363f9d7fc277e72082db6964dcdecd07a40b5c499ebc438
4
+ data.tar.gz: b85536f382ed639c5cecd06a16d148c378ca742f5156be1ad18cc16f4a5116dc
5
5
  SHA512:
6
- metadata.gz: 9c91fa9f3916538d244ffca9456ea089a258fb0701f182d6e40e0fad5c51deec986ac0835e611a3b042cf8c0dc84b27b0a7175a388a9ed38ee34bc34de0a865d
7
- data.tar.gz: 940939975bb206402a13f5c4b1dd8a9f0308fe787fada7e0d59e70a6769eeb960755fd3d4aba7aa480b45cdf9a4c837dfda5382b284c7e5bbb4631d98d4f01ef
6
+ metadata.gz: a91851e7a145ba77b00959e8207a9334f4f7ea798dab4374ea339a61168c3363118b31ebaa6ad919358f957c0947ffece2ac445eb3f3cf512af4a23826910a5d
7
+ data.tar.gz: 5cf55b4b71387efee97919933553c050f4ac5ddf7746f800e63ebb8f8e2d09808778cc949d2725bc1f6ce80eae2bf991aa211ed845ed5c601c675d3be3a51e8d
data/.rubocop.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  require:
2
2
  - rubocop-performance
3
3
  - rubocop-rspec
4
+ - rubocop-factory_bot
5
+ - rubocop-rake
4
6
 
5
7
  AllCops:
6
8
  TargetRubyVersion: 3.0.1
data/CHANGELOG.md CHANGED
@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
10
10
 
11
11
  ### Changes
12
12
  [x] Update ruby gems.
13
+ [x] `dsu import` now has the --override true|false (default: false) OPTION. If true, the import process will ignore the project name found in the import file and import the entries into the current project. If false, the import process will use the project name found in the import file.
13
14
  [x] Change `dsu export` file name for exports. When exporting all DSU entry groups for a project, the file name will be:
14
15
 
15
16
  "dsu-export-<transformed project name>-<timestamp>-all-entry-groups-<from date>-thru-<to date>.csv"
@@ -42,6 +43,7 @@ dsu x dd -f n -t -257
42
43
  dsu-export-default-20240129125946-entry-groups-2023-05-17-thru-2024-01-29.csv
43
44
 
44
45
  ### Bug Fixes
46
+ [x] Fix bug that did not gracefully handle invalid DATEs for the `dsu add --date DATE` command.
45
47
 
46
48
 
47
49
  ## [2.4.4] - 2024-01-28
data/Gemfile CHANGED
@@ -6,14 +6,14 @@ source 'https://rubygems.org'
6
6
  gemspec
7
7
 
8
8
  gem 'dotenv', '~> 2.8', '>= 2.8.1'
9
+ gem 'factory_bot', '~> 6.3'
10
+ gem 'ffaker', '~> 2.21'
11
+ gem 'pry-byebug', '~> 3.9'
9
12
  gem 'rake', '~> 13.0'
13
+ gem 'reek', '~> 6.1', '>= 6.1.1'
10
14
  gem 'rspec', '~> 3.0'
11
15
  gem 'rubocop', '~> 1.50', '>= 1.50.2'
12
16
  gem 'rubocop-performance', '~> 1.19'
17
+ gem 'rubocop-rake', '~> 0.6.0'
13
18
  gem 'rubocop-rspec', '~> 2.23'
14
-
15
- gem 'factory_bot', '~> 6.3'
16
- gem 'ffaker', '~> 2.21'
17
- gem 'pry-byebug', '~> 3.9'
18
- gem 'reek', '~> 6.1', '>= 6.1.1'
19
19
  gem 'simplecov', '~> 0.22.0'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dsu (3.0.0.alpha.4)
4
+ dsu (3.0.0.rc.1)
5
5
  activemodel (>= 7.0.8, < 8.0)
6
6
  activesupport (>= 7.0.8, < 8.0)
7
7
  colorize (>= 1.1, < 2.0)
@@ -32,7 +32,7 @@ GEM
32
32
  colorize (1.1.0)
33
33
  concurrent-ruby (1.2.3)
34
34
  connection_pool (2.4.1)
35
- diff-lcs (1.5.0)
35
+ diff-lcs (1.5.1)
36
36
  docile (1.4.0)
37
37
  dotenv (2.8.1)
38
38
  drb (2.2.0)
@@ -64,7 +64,7 @@ GEM
64
64
  dry-inflector (~> 1.0)
65
65
  dry-logic (~> 1.4)
66
66
  zeitwerk (~> 2.6)
67
- factory_bot (6.4.5)
67
+ factory_bot (6.4.6)
68
68
  activesupport (>= 5.0.0)
69
69
  ffaker (2.23.0)
70
70
  i18n (1.14.1)
@@ -72,7 +72,7 @@ GEM
72
72
  json (2.7.1)
73
73
  language_server-protocol (3.17.0.3)
74
74
  method_source (1.0.0)
75
- minitest (5.21.2)
75
+ minitest (5.22.2)
76
76
  mutex_m (0.2.0)
77
77
  os (1.1.4)
78
78
  parallel (1.24.0)
@@ -95,19 +95,19 @@ GEM
95
95
  rexml (~> 3.1)
96
96
  regexp_parser (2.9.0)
97
97
  rexml (3.2.6)
98
- rspec (3.12.0)
99
- rspec-core (~> 3.12.0)
100
- rspec-expectations (~> 3.12.0)
101
- rspec-mocks (~> 3.12.0)
102
- rspec-core (3.12.2)
103
- rspec-support (~> 3.12.0)
104
- rspec-expectations (3.12.3)
98
+ rspec (3.13.0)
99
+ rspec-core (~> 3.13.0)
100
+ rspec-expectations (~> 3.13.0)
101
+ rspec-mocks (~> 3.13.0)
102
+ rspec-core (3.13.0)
103
+ rspec-support (~> 3.13.0)
104
+ rspec-expectations (3.13.0)
105
105
  diff-lcs (>= 1.2.0, < 2.0)
106
- rspec-support (~> 3.12.0)
107
- rspec-mocks (3.12.6)
106
+ rspec-support (~> 3.13.0)
107
+ rspec-mocks (3.13.0)
108
108
  diff-lcs (>= 1.2.0, < 2.0)
109
- rspec-support (~> 3.12.0)
110
- rspec-support (3.12.1)
109
+ rspec-support (~> 3.13.0)
110
+ rspec-support (3.13.0)
111
111
  rubocop (1.60.2)
112
112
  json (~> 2.3)
113
113
  language_server-protocol (>= 3.17.0)
@@ -128,6 +128,8 @@ GEM
128
128
  rubocop-performance (1.20.2)
129
129
  rubocop (>= 1.48.1, < 2.0)
130
130
  rubocop-ast (>= 1.30.0, < 2.0)
131
+ rubocop-rake (0.6.0)
132
+ rubocop (~> 1.0)
131
133
  rubocop-rspec (2.26.1)
132
134
  rubocop (~> 1.40)
133
135
  rubocop-capybara (~> 2.17)
@@ -145,7 +147,7 @@ GEM
145
147
  tzinfo (2.0.6)
146
148
  concurrent-ruby (~> 1.0)
147
149
  unicode-display_width (2.5.0)
148
- zeitwerk (2.6.12)
150
+ zeitwerk (2.6.13)
149
151
 
150
152
  PLATFORMS
151
153
  x86_64-darwin-19
@@ -163,6 +165,7 @@ DEPENDENCIES
163
165
  rspec (~> 3.0)
164
166
  rubocop (~> 1.50, >= 1.50.2)
165
167
  rubocop-performance (~> 1.19)
168
+ rubocop-rake (~> 0.6.0)
166
169
  rubocop-rspec (~> 2.23)
167
170
  simplecov (~> 0.22.0)
168
171
 
data/lib/dsu/cli.rb CHANGED
@@ -40,7 +40,8 @@ module Dsu
40
40
  desc I18n.t('commands.add.desc'), I18n.t('commands.add.usage')
41
41
  long_desc I18n.t('commands.add.long_desc',
42
42
  date_option_description: date_option_description, mnemonic_option_description: mnemonic_option_description)
43
- option I18n.t('options.date.name'), aliases: I18n.t('options.date.aliases'), type: :string
43
+ option I18n.t('options.date_or_mnemonic.name'), aliases: I18n.t('options.date_or_mnemonic.aliases'),
44
+ type: :string, banner: I18n.t('options.date_or_mnemonic.banner')
44
45
  option I18n.t('options.tomorrow.name'), aliases: I18n.t('options.tomorrow.aliases'), type: :boolean
45
46
  option I18n.t('options.yesterday.name'), aliases: I18n.t('options.yesterday.aliases'), type: :boolean
46
47
  option I18n.t('options.today.name'), aliases: I18n.t('options.today.aliases'), type: :boolean, default: true
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'active_model'
4
4
  require 'json'
5
+ require_relative '../migration/version'
5
6
 
6
7
  module Dsu
7
8
  module Crud
@@ -14,6 +15,10 @@ module Dsu
14
15
  @file_path = file_path
15
16
  end
16
17
 
18
+ def update_version!
19
+ @version = Migration::VERSION
20
+ end
21
+
17
22
  def delete
18
23
  self.class.delete(file_path: file_path)
19
24
  end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../models/migration_version'
4
+ require_relative '../support/fileable'
5
+ require_relative 'version'
6
+
7
+ module Dsu
8
+ module Migration
9
+ class BaseService
10
+ include Support::Fileable
11
+
12
+ def initialize(options: {})
13
+ @options = options || {}
14
+ end
15
+
16
+ class << self
17
+ def migrates_to_latest_migration_version?
18
+ to_migration_version == Migration::VERSION
19
+ end
20
+
21
+ # The migration version that this migration is upgrading from.
22
+ def from_migration_version
23
+ raise NotImplementedError, 'You must implement the #from_migration_version method in your subclass'
24
+ end
25
+
26
+ # The migration version that this migration is upgrading to.
27
+ def to_migration_version
28
+ raise NotImplementedError, 'You must implement the #to_migration_version method in your subclass'
29
+ end
30
+ end
31
+
32
+ def migrate_if!
33
+ return unless run_migration?
34
+
35
+ puts "Running migrations #{from_migration_version} -> #{to_migration_version}..."
36
+ puts "\tpretend?: #{pretend?}" if pretend?
37
+
38
+ run_migration!
39
+ update_migration_version!
40
+
41
+ puts "\tMigration #{from_migration_version} -> #{to_migration_version} complete."
42
+ end
43
+
44
+ private
45
+
46
+ attr_accessor :options
47
+
48
+ # You must implement your own migration logic in your subclass and call this method.
49
+ def run_migration!
50
+ create_backup
51
+ end
52
+
53
+ def pretend?
54
+ options.fetch(:pretend, true)
55
+ end
56
+
57
+ def run_migration?
58
+ migration_version == from_migration_version
59
+ end
60
+
61
+ # The migration version that this migration is upgrading from.
62
+ def from_migration_version
63
+ self.class.from_migration_version
64
+ end
65
+
66
+ # The migration version that this migration is upgrading to.
67
+ def to_migration_version
68
+ self.class.to_migration_version
69
+ end
70
+
71
+ # The migration version before running this migration.
72
+ def migration_version
73
+ # Typically we should not be using models in any of the migration services
74
+ # because if these change, the migrations will break. However, using
75
+ # the MigrationVersion model is an exception because it is a very simple
76
+ # model and is unlikely to change.
77
+ Models::MigrationVersion.new.version
78
+ end
79
+
80
+ def create_backup
81
+ puts "Creating backup #{backup_folder}..."
82
+
83
+ return puts "\tSkipping: backup already exists." if backup_exist?
84
+
85
+ FileUtils.cp_r(dsu_folder, backup_folder)
86
+ FileUtils.cp(config_path, backup_folder)
87
+ end
88
+
89
+ def backup_exist?
90
+ Dir.exist?(backup_folder)
91
+ end
92
+
93
+ def backup_folder
94
+ @backup_folder ||= backup_folder_for(migration_version: from_migration_version)
95
+ end
96
+
97
+ def update_migration_version!
98
+ puts 'Updating migration version...'
99
+
100
+ return if pretend? || migration_version == to_migration_version
101
+
102
+ Models::MigrationVersion.new(version: to_migration_version).save!
103
+ end
104
+
105
+ def seed_data_folder
106
+ seed_data_dsu_folder_for(migration_version: to_migration_version)
107
+ end
108
+
109
+ def seed_data_configuration
110
+ seed_data_dsu_configuration_for(migration_version: to_migration_version)
111
+ end
112
+
113
+ def raise_backup_folder_does_not_exist_error_if!
114
+ raise "Backup folder #{backup_folder} does not exist, cannot continue" unless backup_exist?
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../env'
4
+ require_relative 'version'
5
+
6
+ module Dsu
7
+ module Migration
8
+ class Migrator
9
+ class << self
10
+ def migrate_if!(migration_services: [])
11
+ return if migration_services.any? do |migration_service|
12
+ migration_service.migrate_if!
13
+ migration_service.class.migrates_to_latest_migration_version?
14
+ end
15
+
16
+ raise I18n.t('migrations.error.missing_current_migration_service', migration_version: Migration::VERSION)
17
+ rescue StandardError => e
18
+ puts I18n.t('migrations.error.failed', message: e.message)
19
+ exit 1 unless Dsu.env.test?
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dsu
4
+ module Migration
5
+ module RawHelpers
6
+ module ColorThemeHash
7
+ def to_h
8
+ read.merge(version: version)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dsu
4
+ module Migration
5
+ module RawHelpers
6
+ module ConfigurationHash
7
+ attr_accessor :default_project
8
+
9
+ def to_h
10
+ read.merge(version: version, default_project: default_project)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dsu
4
+ module Migration
5
+ module RawHelpers
6
+ module EntryGroupHash
7
+ def to_h
8
+ read.merge(version: version)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../crud/json_file'
4
+
5
+ module Dsu
6
+ module Migration
7
+ class RawJsonFile < Crud::JsonFile
8
+ public :read, :read!, :version=
9
+
10
+ def to_h
11
+ read.merge(version: version)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'pathname'
5
+
6
+ require_relative 'raw_json_file'
7
+
8
+ module Dsu
9
+ module Migration
10
+ class RawJsonFiles
11
+ attr_reader :folder
12
+
13
+ def initialize(folder)
14
+ @folder = folder
15
+ end
16
+
17
+ def each_file(regex: //)
18
+ return unless folder_exist?
19
+
20
+ Pathname.new(folder).children.each do |child|
21
+ next unless child.file? && child.to_s.match?(regex)
22
+
23
+ yield RawJsonFile.new(child)
24
+ end
25
+ end
26
+
27
+ def folder_exist?
28
+ self.class.folder_exist?(folder: folder)
29
+ end
30
+
31
+ class << self
32
+ def folder_exist?(folder:)
33
+ Dir.exist?(folder)
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ attr_writer :folder
40
+
41
+ def safe_cp_r(source, destination)
42
+ Pathname.new(source).find do |source_path|
43
+ next if source_path.directory?
44
+
45
+ relative_path = source_path.relative_path_from(Pathname.new(source))
46
+ target_path = Pathname.new(destination).join(relative_path)
47
+
48
+ next if target_path.exist?
49
+
50
+ FileUtils.mkdir_p(target_path.dirname)
51
+ FileUtils.cp(source_path, target_path)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../base_service'
4
+ require_relative '../raw_helpers/entry_group_hash'
5
+ require_relative '../version'
6
+
7
+ module Dsu
8
+ module Migration
9
+ module V20230613121411
10
+ class Service < BaseService
11
+ class << self
12
+ def from_migration_version
13
+ 0
14
+ end
15
+
16
+ def to_migration_version
17
+ 20230613121411 # rubocop:disable Style/NumericLiterals
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def run_migration!
24
+ super
25
+
26
+ raise_backup_folder_does_not_exist_error_if!
27
+
28
+ delete_old_config_file
29
+ delete_old_themes_folder
30
+
31
+ copy_new_dsu_folders
32
+ copy_new_dsu_configuration
33
+ migrate_entry_groups
34
+ end
35
+
36
+ def config_file_from
37
+ File.join(root_folder, '.dsu')
38
+ end
39
+
40
+ def dsu_folder_from
41
+ File.join(root_folder, 'dsu')
42
+ end
43
+
44
+ def entries_folder_from
45
+ File.join(dsu_folder_from, 'entries')
46
+ end
47
+
48
+ def themes_folder_from
49
+ File.join(dsu_folder_from, 'themes')
50
+ end
51
+
52
+ def copy_new_dsu_folders
53
+ puts 'Copying new dsu folders...'
54
+
55
+ FileUtils.cp_r(File.join(seed_data_folder, '.'), File.join(root_folder, 'dsu')) unless pretend?
56
+ end
57
+
58
+ def copy_new_dsu_configuration
59
+ puts 'Copying new dsu configuration...'
60
+
61
+ FileUtils.cp(seed_data_configuration, config_folder) unless pretend?
62
+ end
63
+
64
+ def migrate_entry_groups
65
+ puts 'Migrating entry groups...'
66
+
67
+ return if pretend?
68
+
69
+ puts "\tUpdating entry group version..."
70
+
71
+ RawJsonFiles.new(entries_folder_from).each_file(regex: /\d{4}-\d{2}-\d{2}.json/) do |raw_entry_group|
72
+ raw_entry_group.extend(RawHelpers::EntryGroupHash)
73
+ raw_entry_group.version = to_migration_version
74
+ raw_entry_group.save!
75
+ end
76
+ end
77
+
78
+ def delete_old_config_file
79
+ puts 'Deleting old configuration file...'
80
+
81
+ return if pretend?
82
+
83
+ File.delete(config_file_from) if File.file?(config_file_from)
84
+ end
85
+
86
+ def delete_old_themes_folder
87
+ puts 'Deleting old themes folder...'
88
+
89
+ FileUtils.rm_rf(themes_folder_from) unless pretend?
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../base_service'
4
+ require_relative '../raw_helpers/color_theme_hash'
5
+ require_relative '../raw_helpers/configuration_hash'
6
+ require_relative '../raw_helpers/entry_group_hash'
7
+ require_relative '../raw_json_file'
8
+ require_relative '../version'
9
+
10
+ module Dsu
11
+ module Migration
12
+ module V20240210161248
13
+ class Service < BaseService
14
+ class << self
15
+ def from_migration_version
16
+ 20230613121411 # rubocop:disable Style/NumericLiterals
17
+ end
18
+
19
+ def to_migration_version
20
+ 20240210161248 # rubocop:disable Style/NumericLiterals
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def run_migration!
27
+ super
28
+
29
+ raise_backup_folder_does_not_exist_error_if!
30
+
31
+ add_new_color_themes
32
+ create_default_project
33
+ create_current_project_file
34
+ update_configuration
35
+ update_entry_groups
36
+ update_color_themes
37
+ delete_old_entry_folder
38
+
39
+ puts 'Migration completed successfully.'
40
+ end
41
+
42
+ def dsu_folder_from
43
+ File.join(root_folder, 'dsu')
44
+ end
45
+
46
+ def entries_folder_from
47
+ File.join(dsu_folder_from, 'entries')
48
+ end
49
+
50
+ def themes_folder_from
51
+ File.join(dsu_folder_from, 'themes')
52
+ end
53
+
54
+ def add_new_color_themes
55
+ puts 'Copying new color themes...'
56
+
57
+ FileUtils.mkdir_p(themes_folder_from) unless pretend?
58
+
59
+ %w[light.json christmas.json].each do |theme_file|
60
+ destination_theme_file_path = File.join(themes_folder_from, theme_file)
61
+ # Don't skip these theme files because they were deployed in the previous
62
+ # dsu version with bugs. We need to overwrite them with this new version.
63
+ # next if File.exist?(destination_theme_file_path)
64
+
65
+ source_theme_file_path = File.join(seed_data_folder, 'themes', theme_file)
66
+ FileUtils.cp(source_theme_file_path, destination_theme_file_path) unless pretend?
67
+ end
68
+ end
69
+
70
+ def create_default_project
71
+ puts "Creating default project \"#{default_project_name}\"..."
72
+
73
+ return if pretend?
74
+
75
+ FileUtils.cp_r(File.join(seed_data_folder, 'projects', '.'),
76
+ File.join(dsu_folder, 'projects'))
77
+ end
78
+
79
+ def create_current_project_file
80
+ puts 'Creating current project file...'
81
+
82
+ return if pretend?
83
+
84
+ # NOTE: dsu_folder won't change and is safe to use here.
85
+ FileUtils.cp(File.join(seed_data_folder, 'current_project.json'), dsu_folder)
86
+ end
87
+
88
+ def update_configuration
89
+ puts 'Updating configuration...'
90
+
91
+ return if pretend?
92
+
93
+ # NOTE: config_path won't change and is safe to use here.
94
+ RawJsonFile.new(config_path).tap do |configuration_file|
95
+ configuration_file.extend(RawHelpers::ConfigurationHash)
96
+ configuration_file.version = to_migration_version
97
+ configuration_file.default_project = default_project_name
98
+ end.save!
99
+ end
100
+
101
+ def update_entry_groups
102
+ puts 'Updating entry groups...'
103
+
104
+ return if pretend?
105
+
106
+ puts "\tCopying entries to default project \"#{default_project_name}\"..."
107
+
108
+ entries_folder_to = File.join(dsu_folder, 'projects', default_project_name, 'entries')
109
+ FileUtils.cp_r(File.join(entries_folder_from, '.'), entries_folder_to)
110
+
111
+ puts "\tUpdating entry group version..."
112
+
113
+ RawJsonFiles.new(entries_folder_to).each_file(regex: /\d{4}-\d{2}-\d{2}.json/) do |raw_entry_group|
114
+ raw_entry_group.extend(RawHelpers::EntryGroupHash)
115
+ raw_entry_group.version = to_migration_version
116
+ raw_entry_group.save!
117
+ end
118
+ end
119
+
120
+ def update_color_themes
121
+ puts 'Updating color themes...'
122
+
123
+ FileUtils.cp_r(File.join(backup_folder, 'themes', '.'), themes_folder) unless pretend?
124
+
125
+ puts "\tUpdating color theme version..."
126
+
127
+ themes_folder_to = File.join(dsu_folder, 'themes')
128
+
129
+ RawJsonFiles.new(themes_folder_to).each_file(regex: /.+.json/) do |raw_entry_group|
130
+ raw_entry_group.extend(RawHelpers::ColorThemeHash)
131
+ raw_entry_group.version = to_migration_version
132
+ raw_entry_group.save! unless pretend?
133
+ end
134
+ end
135
+
136
+ def delete_old_entry_folder
137
+ puts 'Cleaning up old entries...'
138
+
139
+ FileUtils.rm_rf(File.join(entries_folder_from)) unless pretend?
140
+ end
141
+
142
+ def default_project_name
143
+ 'default'
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end