Odonno / surrealdb-migrations

An awesome SurrealDB migration tool, with a user-friendly CLI and a versatile Rust library that enables seamless integration into any project.
https://crates.io/crates/surrealdb-migrations
MIT License
231 stars 20 forks source link

Feature: Seeding #68

Open itsezc opened 9 months ago

itsezc commented 9 months ago

Is your feature request related to a problem? Please describe.

Seeding is a common feature provided by ORMs and migration tools like Eloquent and Prisma

Describe the solution you'd like

A seed file that is executed when the database is first setup.

Describe alternatives you've considered

Manually running SURQL on setup, but this can be tedious for large operations.

Odonno commented 9 months ago

Interesting.

This is not a feature I am particularly a fan of. But this is a feature most developers would expect. I suppose we can think how to integrate this feature into surrealdb-migrations.

I can think of two ways to run seeds:

  1. Manually, via cli command
  2. Automatically, when migration start from point 0

Additional features on this would be:

itsezc commented 9 months ago

Interesting.

This is not a feature I am particularly a fan of. But this is a feature most developers would expect. I suppose we can think how to integrate this feature into surrealdb-migrations.

I can think of two ways to run seeds:

  1. Manually, via cli command
  2. Automatically, when migration start from point 0

Additional features on this would be:

  • put seed files in a /seeds folder to keep everything in order
  • ability to enable/disable automatic seeding in config file?
  • ability to run bash scripts, or even better to run Rust scripts
  • inform when any seed file is not update (when mismatches are found with the latest version of the schema)

I think both ways should be possible, with automatic seeding if the start point is 0, and these seeds should also be split based on the database branch, for instance you may have test accounts in "dev" or "staging" but not on production.

Having a /seeds folder makes sense, I think having it configurable makes sense with the default behaviour being true and having checks against the latest schema. Not too keen on the running bash scripts tho, perhaps I'm mistaken but I don't see how this might come in handy.

Odonno commented 9 months ago

Even if SurrealDB offers a large set of features, running a script (via bash for example) can be useful in some use cases. Like importing data from a text file or a CSV file. Or creating custom batch operations. This is especially true for seeding.