SQL

1. System Context

Developers use Nitric to define required databases within their application (e.g., referencing a Postgres or MySQL database).

  • App code uses the SQL database resources from the Nitric SDK.
  • Developers can use any language specific client or ORM to interact with the databases.

Operations teams use default or customized Terraform modules to provision the required resources for the SQL database and for running database migrations:

Example AWS Provider
  • AWS RDS (or another SQL provider) hosts the actual database.
  • AWS ECR (Elastic Container Registry) stores the database migration image.
  • AWS CodeBuild runs the migration image against the database on startup.
  • AWS IAM manages roles and policies granting CodeBuild access to pull images from ECR, access VPC resources, and more.
Write Code
Terraform
Provision & Configure
Push/Tag Image
Run Migrations
Manage Permissions
Access Database
Executes SQL Migrations
Developer
Operations
nitric up
AWS RDS (SQL Database)
AWS ECR
AWS CodeBuild (Executes Migrations)
AWS IAM
AWS Lambda Functions

2. Sequence Diagram (Level 2)

ClientNitric SDKNitric RuntimeSQL Database (e.g., PostgreSQL, MySQL)alt[Successful Operation][Failure]Perform SQL operation (e.g., query, insert, update)Forward SQL API callExecute SQL operationReturn result (e.g., query data or success status)Return resultReturn result to clientReturn errorForward errorReturn error responseClientNitric SDKNitric RuntimeSQL Database (e.g., PostgreSQL, MySQL)

3. Component

SQL Resource Module

  • Configures a container registry for storing database migration images, ensuring secure and efficient image management.
  • Dynamically tags and pushes migration images to the registry, streamlining deployment pipelines.
  • Automates the setup of a migration execution environment using containerized tools, enabling seamless database schema updates and initialization.
  • Provides an execution layer for running migrations against the SQL database, with monitoring to ensure successful completion.
  • Abstracts the underlying SQL infrastructure, enabling consistent interactions with relational databases regardless of the cloud provider or database engine (e.g., PostgreSQL, MySQL).
  • Optionally supports provisioning of the SQL database instance or cluster if not pre-existing, ensuring compatibility with the application.
  • Enforces least privilege access by configuring secure roles and policies for database and migration operations, maintaining robust security standards.

4. Code

Developers write application code that uses the SQL database resources from the SDK, and implements the application logic to connect and interact with database.

SDK Reference by language -

Operations will use or extend the Nitric Terraform reference modules:

Last updated on Feb 7, 2025