Skip to content

just db-seed should be idempotent. #306

@rgreinho

Description

@rgreinho

Feature request

A nice to have feature would be to be able to run db-seed several times without error.

Current Behavior

If the database was previously seeded, the seeder script fails because the data is already there:

 bna-api on  docs via 🦀 v1.88.0
╰❯ just db-seed
cargo run --example seeder
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.57s
     Running `target/debug/examples/seeder`
[examples/seeder.rs:235:5] bna_core_services.len() = 10

╭ bna-api on  docs via 🦀 v1.88.0
╰❯ just db-seed
cargo run --example seeder
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.57s
     Running `target/debug/examples/seeder`
Error: Execution Error: error returned from database: duplicate key value violates unique constraint "city_pkey"

Caused by:
   0: error returned from database: duplicate key value violates unique constraint "city_pkey"
   1: error returned from database: duplicate key value violates unique constraint "city_pkey"
   2: duplicate key value violates unique constraint "city_pkey"

Location:
    examples/seeder.rs:225:5
error: Recipe `db-seed` failed on line 77 with exit code 1

Expected Behavior

Not the end of the world, but the script should either provide a nicer error message, or better being idempotent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions