dekiru-data_migration 1.0.0 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5428a8cf5e2a02ff63e8b5a7d3dd2703cf471f60a7bf1dfdd289418a93f1bca
4
- data.tar.gz: d0b1afb0f2d5bad6112849c8f046e90c309a19eddde473bde1cf179e8e2a395a
3
+ metadata.gz: 342d506a7d85aa5b54c2023c5bdd2f13d7ccc968e562bde836571461e67541c8
4
+ data.tar.gz: a30d3c9877ac51fac63dd7a0d69333750e453cd5020ae398b1361428d1185a68
5
5
  SHA512:
6
- metadata.gz: 30e87b497f402579cac1d212f0cc9e12ba4bf8bcc84166de33dbbf9619f9da734c5d468d115801db0b326cffc7dfe09e4ca21b1b7e2c818ecf4848e18bf7c894
7
- data.tar.gz: f5a5b31881fe7485d18ffea31950d70b4a5a05a7f5defd44197ec87b78c454a8db707be376825fc28a010c9f95d0c9584beb50f14965cc508fa211602d4bd226
6
+ metadata.gz: 19478e294f25f04c5757bd1118f9786bd285b1fbb802a9f91aed81db88fb37503c03ef954c30c6e3d1a7c4476c32a6378c499092a68f786ff5dfb17a4903f2d8
7
+ data.tar.gz: bc354a7e66c1960dde53c49ded487dd4ad4a8b9d6cd0e1852f82c8b94f20bdb08f6565329ee751de9622cefd984fa9f3a7771b9feeb71d945e9aa144874d0049
data/README.md CHANGED
@@ -290,3 +290,21 @@ Executes `find_each` with a progress bar for ActiveRecord scopes.
290
290
 
291
291
  ### `each_with_progress(enum, options = {}, &block)`
292
292
  Executes processing with a progress bar for any Enumerable objects.
293
+
294
+ ## Agent Skills
295
+
296
+ This repository provides an agent skill for creating data migration scripts.
297
+
298
+ ### Available Skills
299
+
300
+ #### `data-migration-script`
301
+
302
+ Automatically creates data migration and deletion scripts using the `dekiru-data_migration` gem.
303
+
304
+ **Triggers**: The agent will use this skill when you ask to "create a data migration script", "create a script to delete unnecessary records", or similar requests involving DB operations via scripts (bulk updates, deleting orphaned records, deleting ActiveStorage files, etc.).
305
+
306
+ **Install**:
307
+
308
+ ```bash
309
+ gh skill install SonicGarden/dekiru-data_migration
310
+ ```
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dekiru
4
4
  module DataMigration
5
- VERSION = "1.0.0"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
@@ -0,0 +1,86 @@
1
+ ---
2
+ name: data-migration-script
3
+ description: Skill for creating data migration and deletion scripts using the dekiru-data_migration gem in the social-apartment project. Always use this skill when asked to "create a script using dekiru-data_migration", "create a data migration script", "create a script to delete unnecessary records", or "turn this into a script". Use proactively for DB operations via scripts such as deleting orphaned records after feature removal or code changes, bulk data updates, and deleting ActiveStorage files.
4
+ license: MIT
5
+ ---
6
+
7
+ # Data Migration Script Creation
8
+
9
+ Create data migration and deletion scripts using the `dekiru-data_migration` gem.
10
+
11
+ ## Preliminary Research
12
+
13
+ Before writing a script, confirm the following:
14
+
15
+ 1. **Understand the changes**: Review related Issues and PRs to understand what was deleted or changed
16
+ 2. **Identify target records**: Check the schema (`db/schema.rb`) and current model code to identify the conditions for records that need to be deleted or updated
17
+
18
+ ## Script Creation Steps
19
+
20
+ ### 1. Generate a file with the generator
21
+
22
+ ```bash
23
+ bin/rails generate maintenance_script <PascalCaseName>
24
+ ```
25
+
26
+ - `<PascalCaseName>` is the name describing the operation in PascalCase (e.g., `DeleteDeliveryNotificationImages`)
27
+ - Generated file: `scripts/YYYYMMDD_delete_delivery_notification_images.rb`
28
+ - Today's date (8 digits) is automatically appended to the class name
29
+
30
+ ### 2. Edit the generated file
31
+
32
+ Implement `migration_targets` and `migrate_record` in the generated file.
33
+
34
+ ### Common Operation Patterns
35
+
36
+ **Deleting ActiveStorage attachments**:
37
+ ```ruby
38
+ def migration_targets
39
+ ActiveStorage::Attachment.where(record_type: 'ModelName', name: 'attachment_name')
40
+ end
41
+
42
+ def migrate_record(record)
43
+ record.purge # synchronously delete attachment and blob
44
+ end
45
+ ```
46
+
47
+ **Updating record attributes**:
48
+ ```ruby
49
+ def migrate_record(record)
50
+ record.update!(attribute: new_value)
51
+ end
52
+ ```
53
+
54
+ **Deleting records**:
55
+ ```ruby
56
+ def migrate_record(record)
57
+ record.destroy!
58
+ end
59
+ ```
60
+
61
+ **Conditional skip**:
62
+ ```ruby
63
+ def migrate_record(record)
64
+ return if record.some_condition?
65
+ record.update!(...)
66
+ end
67
+ ```
68
+
69
+ ## Execution and Verification Commands
70
+
71
+ ```bash
72
+ # Check target record count (before execution)
73
+ bin/rails runner "p TargetModel.where(...).count"
74
+
75
+ # Run the script
76
+ bin/rails runner scripts/YYYYMMDD_description.rb
77
+
78
+ # Verify after execution
79
+ bin/rails runner "p TargetModel.where(...).count"
80
+ ```
81
+
82
+ ## Notes
83
+
84
+ - `purge` deletes synchronously (immediately removes from storage). Use `purge_later` for async deletion
85
+ - `migration_targets` must return an ActiveRecord relation (processed in batches via `find_each`)
86
+ - Always verify the target record count before running in production
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dekiru-data_migration
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SonicGarden
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-06-30 00:00:00.000000000 Z
10
+ date: 2026-05-04 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -65,6 +65,7 @@ files:
65
65
  - sig/dekiru/data_migration.rbs
66
66
  - sig/dekiru/data_migration/migration.rbs
67
67
  - sig/dekiru/data_migration/operator.rbs
68
+ - skills/data-migration-script/SKILL.md
68
69
  homepage: https://github.com/SonicGarden/dekiru-data_migration
69
70
  licenses:
70
71
  - MIT