Module Phase4_backend

Step to migrate backend/setup.sh:

  1. Check `Cargo.toml`
  2. Check `.env`: if it is missing, check for `.env.example`. if `.env.example` exists, copy it to `.env`
  1. Read the `.env` to understand about the database environment
  2. Parse `.env` and get the `DATABASE_URL`
  3. Detech database type: localhost, or supabase?
  1. Install SQLx CLI: check `sqlx` command is available. If not install it.
  2. Run Database Migrations: `sqlx migrate run` within the backend folder.
  3. Build the project: `cargo build` in the backend folder.

----- Service and Database Management These steps handle the "stateful" parts of the environment, such as runnning services, verifying the database state. They can be implemented after the core logic is working.

  1. Condition Execution: only run this step if the database type from Step 2 is `local`
  2. Start PostgreSQL: Execute the system command to start the PostgreSQL service.
  3. Start Redis: Execute the system command to start the Redis service.
  1. Test connection: ++ For `Supabase`, verify the connection to the remote database. ++ For `Local`, verify the connection to the local PostgreSQL instance.
  2. Verify Schema: Implement a basic schema check (e.g., query for the existence of a key table created by the migrations.) Depend on step 3, and for a local setup, the service must be running (step 4)

---- Post-Setup Enhancements

This final setp is a "nice-to-have" that confirms the running application is working correctly.

Step 6: Live Server Health Check (Depend on step 3) Briefly start the backend server and test its main API endpoints to confirm the build was successful and the server can run.

  1. Start Server: Run `cargo run`
  2. Health Check: After a short delay, use an OCaml HTTP client library to make requests to `http://localhost:3000/api/bugets/overview` and other key endpoints.
  3. Stop Server: Terminate the background server process after the checks are complete.
val setup_backend : string -> Types.phase_result