Fork me on GitHub
#duct
<
2018-02-07
>
dadair19:02:17

I’m adding an integrant key for seeding my database, so that I can do lein run :my-ns/seeder, similar to rake db:seed. I know I can prevent it from being initialized automatically in production by not inheriting from :duct/daemon; but is there a way to exclude it from initialization, even in development? I suppose I could filter it out in dev.clj prior to (duct/read-config ..)?

weavejester19:02:09

@dadair You can filter it out of the map, but a more robust solution would be to make it idempotent.

dadair19:02:12

so more along the lines of having a (when (requires-seeds? db) (seed! db)) in the init-key handler?

weavejester19:02:28

Something like that. It ensures the seeding function is safe no matter how it’s applied. Ideally, if an old seed is applied, a newer seed should replace it.

dadair19:02:08

I suppose I could replicate something along the lines of the ragtime_migrations table

weavejester19:02:28

It depends on how your database is set up, and whether the seed is constant between production and development.

weavejester20:02:33

You could use a migration for it if it was constant.

dadair20:02:59

Initially it was a migration but we want to move it into proper clj files to have more programmatic control (lots of interrelated baseline records). I think your comment on idempotency is the correct approach.

weavejester20:02:12

A custom migration record might be a solution. So long as it satisfies the ragtime.protocols/Migration protocol.

weavejester20:02:07

On the other hand, it might not be desirable to tie the seed to the migrations if they are sufficiently unrelated.