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
@@ -1,178 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../support/fileable'
4
- require_relative 'version'
5
-
6
- # TODO: Read raw configuration .json file
7
- # If default_project is not set...
8
- # - Add default_project to configuration .json file and write it out.
9
- # - Reload the configuration file.
10
- # - Create a Models::Project object for the default project and initialize/save it.
11
- # - Move the old entries folder into the default project folder.
12
- # TODO: Add default_project to configuration .json file
13
- module Dsu
14
- module Migration
15
- class Service20230613121411
16
- include Support::Fileable
17
-
18
- def initialize(options: {})
19
- @options = options || {}
20
- end
21
-
22
- def migrate!
23
- puts 'Running migrations...'
24
- puts
25
-
26
- puts "options[:pretend] is true\n" if pretend?
27
-
28
- raise_wrong_migration_version_error_if!
29
-
30
- puts "Migrating from: #{target_migration_version} to version: #{Migration::VERSION}"
31
- puts
32
-
33
- add_new_color_themes
34
- create_backup
35
- create_default_project
36
- update_configuration
37
- update_entry_groups
38
- update_color_themes
39
- update_migration_version
40
- delete_old_entry_folder
41
-
42
- puts 'Migration completed successfully.'
43
- end
44
-
45
- private
46
-
47
- attr_reader :options
48
-
49
- def pretend?
50
- options.fetch(:pretend, true)
51
- end
52
-
53
- def add_new_color_themes
54
- puts 'Copying new color themes...'
55
- puts
56
-
57
- %w[light.json christmas.json].each do |theme_file|
58
- destination_theme_file_path = File.join(Dsu::Support::Fileable.themes_folder, theme_file)
59
- next if File.exist?(destination_theme_file_path)
60
-
61
- source_theme_file_path = File.join(Dsu::Support::Fileable.seed_data_folder, 'themes', theme_file)
62
- FileUtils.cp(source_theme_file_path, destination_theme_file_path) unless pretend?
63
- puts I18n.t('migrations.information.theme_copied', from: source_theme_file_path, to: destination_theme_file_path)
64
- end
65
- end
66
-
67
- def create_backup
68
- return if Dir.exist?(backup_folder)
69
-
70
- puts 'Creating backup...'
71
- puts
72
-
73
- FileUtils.cp_r(dsu_folder, backup_folder) unless pretend?
74
- end
75
-
76
- def create_default_project
77
- default_project = Models::Configuration::DEFAULT_CONFIGURATION[:default_project]
78
- return if Models::Project.project_initialized?(project_name: default_project)
79
-
80
- puts "Creating default project \"#{default_project}\"..."
81
- puts
82
-
83
- Models::Project.create(project_name: default_project, options: options) unless pretend?
84
- end
85
-
86
- def update_configuration
87
- puts 'Updating configuration...'
88
- puts
89
-
90
- return if pretend?
91
-
92
- Models::Configuration.new.tap do |configuration|
93
- configuration.version = Dsu::Migration::VERSION
94
- configuration.write!
95
- end
96
- end
97
-
98
- def update_entry_groups
99
- puts 'Updating entry groups...'
100
- puts
101
-
102
- return if pretend? || Dir.exist?(entries_folder)
103
-
104
- puts 'Copying entries to default project...'
105
- puts
106
-
107
- FileUtils.mkdir_p(entries_folder)
108
- FileUtils.cp_r(File.join(backup_folder, 'entries', '.'), entries_folder)
109
-
110
- puts 'Updating entry group version...'
111
- puts
112
-
113
- Models::EntryGroup.all.each do |entry_group|
114
- puts "Updating entry group version: #{entry_group.time_yyyy_mm_dd}..."
115
- entry_group.version = Dsu::Migration::VERSION
116
- entry_group.save! unless pretend?
117
- end
118
- end
119
-
120
- def update_color_themes
121
- puts 'Updating color themes...'
122
- puts
123
-
124
- return if pretend? || Dir.exist?(themes_folder)
125
-
126
- puts 'Copying color themes...'
127
- puts
128
-
129
- FileUtils.mkdir_p(themes_folder)
130
- FileUtils.cp_r(File.join(backup_folder, 'themes', '.'), themes_folder)
131
-
132
- puts 'Updating color theme version...'
133
- puts
134
-
135
- Models::ColorTheme.all.each do |color_theme|
136
- puts "Updating color theme version: #{color_theme.theme_name}..."
137
- color_theme.version = Dsu::Migration::VERSION
138
- color_theme.save! unless pretend?
139
- end
140
- end
141
-
142
- def update_migration_version
143
- puts 'Updating migration version...'
144
- puts
145
-
146
- return if pretend? || migration_version == Migration::VERSION
147
-
148
- Models::MigrationVersion.new(version: Migration::VERSION).save!
149
- end
150
-
151
- def delete_old_entry_folder
152
- puts 'Cleaning up old entries...'
153
- puts
154
-
155
- FileUtils.rm_rf(File.join(dsu_folder, 'entries')) unless pretend?
156
- end
157
-
158
- def backup_folder
159
- @backup_folder ||= File.join(root_folder, "dsu-#{target_migration_version}-backup")
160
- end
161
-
162
- def target_migration_version
163
- 20230613121411 # rubocop:disable Style/NumericLiterals
164
- end
165
-
166
- def raise_wrong_migration_version_error_if!
167
- return if migration_version == target_migration_version
168
-
169
- raise "Actual migration version #{migration_version} " \
170
- "is not the expected migration version #{target_migration_version}."
171
- end
172
-
173
- def migration_version
174
- @migration_version ||= Models::MigrationVersion.new.version
175
- end
176
- end
177
- end
178
- end