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 +4 -4
- data/README.md +31 -3
- data/lib/fixture_seed/railtie.rb +4 -2
- data/lib/fixture_seed/version.rb +1 -1
- data/lib/fixture_seed.rb +0 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3017e602e40c59de792d03c63f0d126c06abb63e54476329c1c88e9d36a6f57a
|
4
|
+
data.tar.gz: c8c7267e55089bc38ae585e3d0329038a2416205da9ba9e4d9997674436ae891
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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
|
|
data/lib/fixture_seed/railtie.rb
CHANGED
@@ -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
|
12
|
-
|
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
|
data/lib/fixture_seed/version.rb
CHANGED
data/lib/fixture_seed.rb
CHANGED