spinframework / spinframework/spin

Initialization Tasks (e.g. creating database / seeding data)

Open
#2,443 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
6.5k
Forks
310
Avg merge
1d 20h
Merged PRs (30d)
24

Description

Developers can use the --sqlite flag as part of spin up and provide SQL commands to perform common tasks like executing DDL and/or DML before the actual Spin App bootstraps. Although this is great and useful for some situations, there are currently limitations:

  • Only available for SQLite
  • Only affects the default database

Facing those limitations results in developers coming up with different patterns, layouts, scripts, or make targets to bootstrap databases before running their Spin App. I think we could improve Spin here and make it more holistic to provide a general purpose initialization stage.

From DX point of view I would love to have a unified experience to perform initialization logic. Although I had different potential solutions in my mind, I wanna share my personal favorite approach here:

Wouldn't it be possible to provide an additional macro and let developers "code" their initialization logic? I'm thinking about something like shown below. 👇🏻


#[initialize]
pub fn initialize() -> anyhow::Result<()> {
  // perform initialization logic
}

#[http_component]
pub fn handle_req(req: Request) -> anyhow::Result<impl IntoResponse> {
  Ok(Response::new(200,())
}

This would allow developers to use variables, and environment variables configured in their spin.toml and to run initialization logic - like database seeding, no matter which DBMS they use.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests; start by tracing the existing spin up --sqlite initialization path and how Spin apps bootstrap. Compare that behavior with the proposed #[initialize] entry point, then define the supported initialization scope and verify that the resulting design works beyond SQLite and the default database.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend, databases, developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.