fixture_seed 0.1.0 → 0.2.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: 4b756a4004e83e2c69aac4a24fc69391e646fafa774d79b547b65b8d6fa58df7
4
- data.tar.gz: 7790869a088bd54a43a5881da34885c7b79c9ea0360c6601ef0314e34d925067
3
+ metadata.gz: 3017e602e40c59de792d03c63f0d126c06abb63e54476329c1c88e9d36a6f57a
4
+ data.tar.gz: c8c7267e55089bc38ae585e3d0329038a2416205da9ba9e4d9997674436ae891
5
5
  SHA512:
6
- metadata.gz: 70a2b5e3514bef02dccec7ad3ecb97b7cc7742236838531ba7688b8f54884c3b57cd796dbea9828ac261453ba896c308088b9a308f2cdbc49fce1e406247961e
7
- data.tar.gz: 469c9859bd06c963550e6426df5c6cf2805f795abacf3a56863b6b695302d5a2fb8edc07b1c4d87770f2f51e5721693a1e5e530ba6cd8efec36e7afcf6168294
6
+ metadata.gz: 6c7af8d978f4b93ce5175106c08522923e4e1e287d9aee354c432e6526a0e677f64d2cde17bff6dc53b9122f5c3cbb69033f03beaa826fdfd4f81c80d2412d24
7
+ data.tar.gz: 57622614a7ed6514e1e9522ca62a11b2c69e3207f8caaa7e484f22757e994e3b44e4e3726d8ecd067134f7090f9c240a3f185e7f14f629170df23fe44bc2404f
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # FixtureSeed
2
2
 
3
- FixtureSeed is a Rails gem that automatically loads YAML fixture files from the `db/fixtures/` directory when running `rails db:seed`. It loads the fixtures in alphabetical order and handles foreign key constraint errors by retrying failed inserts after all other fixtures are loaded.
3
+ FixtureSeed is a Rails gem that automatically loads YAML fixture files from the `db/fixtures/` directory before running `rails db:seed`. It loads the fixtures in alphabetical order and handles foreign key constraint errors by retrying failed inserts after all other fixtures are loaded.
4
4
 
5
5
  ## Installation
6
6
 
@@ -52,9 +52,37 @@ user2:
52
52
 
53
53
  The labels (e.g., `user1`, `user2`) should follow the pattern of the table name in singular form followed by a number.
54
54
 
55
- ### Loading Order
55
+ ### Fixture Loading Order
56
56
 
57
- Fixtures are loaded in alphabetical order by filename. However, if a fixture fails to load due to foreign key constraints, it will be retried after all other fixtures have been processed.
57
+ #### Order-independent Loading
58
+
59
+ FixtureSeed supports **order-independent loading**, which means you don't need to worry about the loading order of your fixture files based on database relationships.
60
+
61
+ #### How it works
62
+
63
+ 1. Fixtures are initially loaded in alphabetical order by filename
64
+ 2. When a fixture fails to load due to foreign key constraints, it's automatically retried later
65
+ 3. The gem continues processing other fixtures and comes back to failed ones
66
+ 4. This process repeats until all fixtures are loaded or no progress can be made
67
+
68
+ #### Benefits
69
+
70
+ - **No manual dependency management**: You don't need to rename files or organize them based on foreign key relationships
71
+ - **Simplified fixture organization**: Focus on logical grouping rather than loading order
72
+ - **Robust loading**: Handles complex relationships automatically
73
+ - **Error resilience**: Temporary constraint violations don't stop the entire process
74
+
75
+ #### Example
76
+
77
+ Even if your fixtures have dependencies like this:
78
+ ```
79
+ db/fixtures/
80
+ comments.yml # depends on posts and users
81
+ posts.yml # depends on users
82
+ users.yml # no dependencies
83
+ ```
84
+
85
+ FixtureSeed will automatically handle the loading order, ensuring `users.yml` loads first, then `posts.yml`, and finally `comments.yml`, regardless of alphabetical order.
58
86
 
59
87
  ## Development
60
88
 
@@ -8,8 +8,10 @@ module FixtureSeed
8
8
 
9
9
  rake_tasks do
10
10
  if Rake::Task.task_defined?("db:seed")
11
- Rake::Task["db:seed"].enhance do
12
- Rails.logger.info "[FixtureSeed] Starting to load fixtures through db:seed enhancement"
11
+ Rake::Task["db:seed"].enhance([:load_fixtures])
12
+
13
+ task :load_fixtures do
14
+ Rails.logger.info "[FixtureSeed] Starting to load fixtures before db:seed"
13
15
  FixtureSeed.load_fixtures
14
16
  Rails.logger.info "[FixtureSeed] Finished loading fixtures"
15
17
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FixtureSeed
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/fixture_seed.rb CHANGED
@@ -78,7 +78,6 @@ module FixtureSeed
78
78
  end
79
79
 
80
80
  def log_loading(file)
81
- table_name = File.basename(file, ".yml")
82
81
  Rails.logger.info "[FixtureSeed] Loading fixture #{File.basename(file)}..."
83
82
  end
84
83
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixture_seed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Komagata