data-migration 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +38 -8
  4. data/data-migration.gemspec +27 -15
  5. data/lib/data-migration.rb +1 -1
  6. data/lib/data_migration/config.rb +1 -1
  7. data/lib/data_migration/job.rb +27 -9
  8. data/lib/data_migration/task.rb +22 -19
  9. data/lib/generators/data_migration/install_generator.rb +28 -0
  10. data/lib/generators/{templates → data_migration/templates}/install_data_migration_tasks.rb.tt +4 -0
  11. metadata +187 -67
  12. data/.editorconfig +0 -14
  13. data/.github/dependabot.yml +0 -27
  14. data/.github/workflows/_trunk_check.yml +0 -15
  15. data/.github/workflows/test.yml +0 -42
  16. data/.gitignore +0 -24
  17. data/.ruby-version +0 -1
  18. data/.trunk/.gitignore +0 -9
  19. data/.trunk/configs/.markdownlint.yaml +0 -2
  20. data/.trunk/configs/.shellcheckrc +0 -7
  21. data/.trunk/configs/.yamllint.yaml +0 -7
  22. data/.trunk/trunk.yaml +0 -39
  23. data/.vscode/extensions.json +0 -18
  24. data/.vscode/settings.json +0 -7
  25. data/Gemfile +0 -3
  26. data/Gemfile.lock +0 -246
  27. data/lib/generators/install_generator.rb +0 -17
  28. data/spec/data_migration/config_spec.rb +0 -116
  29. data/spec/data_migration/job_spec.rb +0 -96
  30. data/spec/data_migration/task_spec.rb +0 -152
  31. data/spec/data_migration_spec.rb +0 -65
  32. data/spec/fixtures/data_migrations/20241206200111_create_users.rb +0 -17
  33. data/spec/fixtures/data_migrations/20241206200112_create_bad_users.rb +0 -5
  34. data/spec/fixtures/data_migrations/20241206200113_change_users.rb +0 -5
  35. data/spec/fixtures/data_migrations/20241206200114_create_batch_users.rb +0 -9
  36. data/spec/fixtures/schema.rb +0 -26
  37. data/spec/generators/install_generator_spec.rb +0 -48
  38. data/spec/generators/migration_generator_spec.rb +0 -50
  39. data/spec/rails_helper.rb +0 -21
  40. data/spec/spec_helper.rb +0 -30
  41. data/spec/support/junit_formatter.rb +0 -6
  42. data/spec/support/rails_helpers.rb +0 -53
  43. data/usr/bin/release.sh +0 -35
@@ -1,5 +0,0 @@
1
- class CreateGoodUsers
2
- def perform(**kwargs)
3
- User.find_or_create_by(email: "test@example.com")
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- class ChangeUsers
2
- def change(**kwargs)
3
- User.find_or_create_by(email: "test@example.com")
4
- end
5
- end
@@ -1,9 +0,0 @@
1
- class CreateBatchUsers
2
- def perform(index: 1, background: false)
3
- return if index > 2
4
-
5
- User.find_or_create_by(email: "test_#{index}@example.com")
6
-
7
- enqueue(index: index + 1, background: background)
8
- end
9
- end
@@ -1,26 +0,0 @@
1
- ActiveRecord::Schema.define(version: 2024_12_06_200411) do
2
- create_table :data_migration_tasks, force: true do |t|
3
- t.string "name", null: false
4
-
5
- t.json "kwargs", default: {}, null: false
6
- t.json "current_jobs", default: {}, null: false
7
-
8
- t.string "status"
9
- t.datetime "started_at"
10
- t.datetime "completed_at"
11
-
12
- t.bigint "operator_id"
13
- t.string "operator_type"
14
-
15
- t.integer "pause_minutes", default: 0, null: false
16
- t.integer "jobs_limit"
17
-
18
- t.datetime "created_at", null: false
19
- t.datetime "updated_at", null: false
20
- end
21
-
22
- create_table :users, force: true do |t|
23
- t.string :email
24
- t.string :version
25
- end
26
- end
@@ -1,48 +0,0 @@
1
- require "spec_helper"
2
-
3
- require "generators/install_generator"
4
-
5
- describe InstallGenerator, type: :generator do
6
- include FileUtils
7
-
8
- subject(:generator) { described_class.start params }
9
-
10
- let(:root_path) { rails_root(File.expand_path("../../../tmp/rspec", __FILE__)) }
11
-
12
- let(:migration_name) { "data_migration_tasks" }
13
- let(:params) { [migration_name] }
14
- let(:created_files) { Dir["#{root_path}/db/migrate/*_#{migration_name}.rb"] }
15
- let(:migration_content) { File.readlines(created_files.first).reject(&:blank?).map(&:strip) }
16
-
17
- before do
18
- mkdir_p root_path.to_s
19
- allow(DataMigration.config).to receive(:schema_migrations_path).and_return("#{root_path}/db/migrate")
20
- allow(Rails).to receive(:root).and_return(root_path)
21
- end
22
-
23
- after do
24
- rm_rf root_path.to_s
25
- end
26
-
27
- it "creates a migration file" do
28
- generator
29
-
30
- expect(created_files).not_to be_empty
31
-
32
- expect(migration_content).to include("create_table :data_migration_tasks, force: true do |t|")
33
- end
34
-
35
- context "when tasks_table_name is not default" do
36
- before do
37
- allow(DataMigration).to receive(:tasks_table_name).and_return("other_data_migration_tasks")
38
- end
39
-
40
- it "creates a migration file with the correct table name" do
41
- generator
42
-
43
- expect(created_files).not_to be_empty
44
-
45
- expect(migration_content).to include("create_table :other_data_migration_tasks, force: true do |t|")
46
- end
47
- end
48
- end
@@ -1,50 +0,0 @@
1
- require "spec_helper"
2
-
3
- require "generators/data_migration_generator"
4
-
5
- describe DataMigrationGenerator, type: :generator do
6
- include FileUtils
7
-
8
- subject(:generator) { described_class.start params }
9
-
10
- let(:root_path) { rails_root(File.expand_path("../../../tmp/rspec", __FILE__)) }
11
-
12
- let(:migration_name) { "create_users" }
13
- let(:params) { [migration_name] }
14
- let(:created_files) { Dir["#{root_path}/db/data_migrations/*_#{migration_name}.rb"] }
15
- let(:migration_content) { File.readlines(created_files.first).reject(&:blank?).map(&:strip) }
16
-
17
- before do
18
- mkdir_p root_path.to_s
19
- allow(DataMigration.config).to receive(:data_migrations_path).and_return("#{root_path}/db/data_migrations")
20
- allow(Rails).to receive(:root).and_return(root_path)
21
- end
22
-
23
- after do
24
- rm_rf root_path.to_s
25
- end
26
-
27
- it "creates a migration file" do
28
- generator
29
-
30
- expect(created_files).not_to be_empty
31
-
32
- expect(migration_content).to include("class CreateUsers")
33
- expect(migration_content).to include("def perform(**kwargs)")
34
- expect(migration_content).to include("RSpec.describe CreateUsers, type: :data_migration do")
35
- end
36
-
37
- context "when generate_spec is false" do
38
- before do
39
- DataMigration.config.generate_spec = false
40
- end
41
-
42
- it "does not add RSpec describe block" do
43
- generator
44
-
45
- expect(created_files).not_to be_empty
46
-
47
- expect(migration_content).not_to include("RSpec.describe CreateUsers, type: :data_migration do")
48
- end
49
- end
50
- end
data/spec/rails_helper.rb DELETED
@@ -1,21 +0,0 @@
1
- require "active_record"
2
-
3
- require "data-migration"
4
-
5
- require "support/rails_helpers"
6
-
7
- RSpec.configure do |config|
8
- include RailsHelpers
9
-
10
- config.before(:suite) do
11
- ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
12
- load File.expand_path("../fixtures/schema.rb", __FILE__)
13
- end
14
-
15
- config.before(:each) do
16
- tables = ActiveRecord::Base.connection.tables
17
- tables.each do |table|
18
- ActiveRecord::Base.connection.execute("DELETE FROM #{table}")
19
- end
20
- end
21
- end
data/spec/spec_helper.rb DELETED
@@ -1,30 +0,0 @@
1
- require "simplecov"
2
- SimpleCov.start do
3
- add_filter "/spec/"
4
- add_filter { |source_file| source_file.lines.count < 5 }
5
- end
6
-
7
- require "simplecov-cobertura"
8
- SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
9
-
10
- require "active_record"
11
-
12
- require "data-migration"
13
-
14
- Dir[File.expand_path("support/**/*.rb", __dir__)].each { |f| require_relative f }
15
-
16
- RSpec.configure do |config|
17
- include RailsHelpers
18
-
19
- config.before(:suite) do
20
- ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
21
- load File.expand_path("../fixtures/schema.rb", __FILE__)
22
- end
23
-
24
- config.before(:each) do
25
- tables = ActiveRecord::Base.connection.tables
26
- tables.each do |table|
27
- ActiveRecord::Base.connection.execute("DELETE FROM #{table}")
28
- end
29
- end
30
- end
@@ -1,6 +0,0 @@
1
- if ENV["CI"]
2
- require "rspec_junit_formatter"
3
- RSpec.configure do |config|
4
- config.add_formatter RspecJunitFormatter, "coverage/junit-coverage.xml"
5
- end
6
- end
@@ -1,53 +0,0 @@
1
- module RailsHelpers
2
- class User < ActiveRecord::Base
3
- self.table_name = "users"
4
- end
5
-
6
- def rails_root(destination_root = File.expand_path("../../tmp/rspec", __dir__))
7
- Class.new do
8
- def initialize(destination_root)
9
- @destination_root = destination_root
10
- end
11
-
12
- def to_s
13
- @destination_root
14
- end
15
-
16
- def join(*args)
17
- File.join(@destination_root, *args)
18
- end
19
- end.new(destination_root)
20
- end
21
-
22
- def rails_env(env = "development")
23
- Class.new do
24
- def initialize(env)
25
- @env = env.to_s
26
- end
27
-
28
- def development?
29
- @env == "development"
30
- end
31
-
32
- def test?
33
- @env == "test"
34
- end
35
-
36
- def production?
37
- @env == "production"
38
- end
39
-
40
- def to_s
41
- @env
42
- end
43
- end.new(env)
44
- end
45
-
46
- def rails_logger
47
- Class.new do
48
- def info(message)
49
- puts message
50
- end
51
- end.new
52
- end
53
- end
data/usr/bin/release.sh DELETED
@@ -1,35 +0,0 @@
1
- #!/bin/bash
2
-
3
- set -e
4
-
5
- e() {
6
- GREEN='\033[0;32m'
7
- NC='\033[0m'
8
- echo -e "${GREEN}$1${NC}"
9
- eval "$1"
10
- }
11
-
12
- e "bundle"
13
- e "bundle exec rspec"
14
-
15
- if [[ $(git diff --shortstat 2>/dev/null | tail -n1) != "" ]]; then
16
- echo -e "\033[1;31mgit working directory not clean, please commit your changes first \033[0m"
17
- exit 1
18
- fi
19
-
20
- GEM_NAME="data-migration"
21
- VERSION=$(grep -Eo "VERSION\s*=\s*\".+\"" lib/data-migration.rb | grep -Eo "[0-9.]{5,}")
22
- GEM_FILE="$GEM_NAME-$VERSION.gem"
23
-
24
- e "gem build $GEM_NAME.gemspec"
25
-
26
- echo "Ready to release $GEM_FILE $VERSION"
27
- read -p "Continue? [Y/n] " answer
28
- if [[ "$answer" != "Y" ]]; then
29
- echo "Exiting"
30
- exit 1
31
- fi
32
-
33
- e "gem push $GEM_FILE"
34
- e "git tag $VERSION && git push --tags"
35
- e "gh release create $VERSION --generate-notes"