Module Phase4_backend
Step to migrate backend/setup.sh:
- Check `Cargo.toml`
- Check `.env`: if it is missing, check for `.env.example`. if `.env.example` exists, copy it to `.env`
- Step 2: Environment Parsing and Database Detection (depend on step 1)
- Read the `.env` to understand about the database environment
- Parse `.env` and get the `DATABASE_URL`
- Detech database type: localhost, or supabase?
- Step 3: Core Build and Migration (depend on 2)
- Install SQLx CLI: check `sqlx` command is available. If not install it.
- Run Database Migrations: `sqlx migrate run` within the backend folder.
- 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.
- Step 4: Local Service Management (Depend on step 2)
- Condition Execution: only run this step if the database type from Step 2 is `local`
- Start PostgreSQL: Execute the system command to start the PostgreSQL service.
- Start Redis: Execute the system command to start the Redis service.
- Step 5: Database Verification (Depend on step 3 and 4) Perfom checks to ensure the database is correctly set up and the connection is working.
- Test connection: ++ For `Supabase`, verify the connection to the remote database. ++ For `Local`, verify the connection to the local PostgreSQL instance.
- 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.
- Start Server: Run `cargo run`
- 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.
- Stop Server: Terminate the background server process after the checks are complete.