Closed kaspth closed 1 year ago
I got it working recursively!
So now we generate this:
# db/seeds.rb
Oaken.prepare do
register Menu::Item
seed :accounts, :data
end
# db/seeds/test/accounts/demo.rb
accounts.create :demo, name: "Demonstrable Inc."
# There's an extra newline in this file when there's no dependents, but that's a rare case so we probably don't see that live.
# db/seeds/test/accounts/kaspers_donuts.rb
kaspers_donuts = accounts.create :kaspers_donuts, name: "Kasper's Donuts"
donuts = menus.create :donuts, account: kaspers_donuts
menu_items.create :plain_donut, menu: donuts, name: "Plain", price_cents: 1000
menu_items.create :sprinkled_donut, menu: donuts, name: "Sprinkled", price_cents: 1010
users.create :kasper, name: "Kasper", accounts: [kaspers_donuts]
users.create :coworker, name: "Coworker", accounts: [kaspers_donuts]
Ok, now we're also generating data seed files for any unreferenced data segmented by table.
So these:
# test/fixtures/plans.yml
test_premium:
title: Test Premium
price_cents: 20_00
# test/fixtures/users.yml
super_supporter:
name: Super Supporter
Will generate:
# db/seeds/test/data/plans.rb
plans.create :test_premium, title: "Test Premium", price_cents: 2000 # Note we can't preserve the `_`
# db/seeds/test/data/users.rb
users.create :super_supporter, name: "Super Supporter"
There's some strange newlines generated somewhere, but that'll be for tomorrow.
Right now our converter can take a structure like this:
And then when run with
bin/rails g oaken:convert:fixtures --root-model=Account --no-keeps
build:So we can recognize anything that references the account directly and put it into the right file.
We don't recognize second-level connections, e.g.
menu/items.yml
should be inaccounts/kaspers_donuts.rb
and I'm wondering if we should even bother. If we just generate the Oaken syntax and put everything into a file likedb/seeds/test/FIXTURES_TO_ASSOCIATE.rb
that looks like:Then people can copy paste into the right file by matching the variable name, e.g. find which account file has the
donuts
variable frommenu: donuts
.