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

Build Sequence

Below is the sequence of events that occur when a developer registers a SQL database with Nitric.

App Worker(s)Nitric SDKNitric CLINitric Provider (plugin)IaC (e.g. Terraform)Register SQL DatabaseRegister SQL DatabaseForward Nitric SpecProvision Database ClusterProvision Database InstanceProvision IAMApp Worker(s)Nitric SDKNitric CLINitric Provider (plugin)IaC (e.g. Terraform)

Runtime Sequence

Below is the runtime flow of a database operation in a Nitric application, using the Nitric SDK. The SDK provides access to the connection details for the SQL database. All database operations are performed as usual, without any additional Nitric-specific steps.

App CodeNitric SDKNitric Runtime (plugin)Cloud DMBS (e.g. AWS RDS)connectionString()Forward RequestConvert RequestRetrieve Connection StringExecute SQL QueryApp CodeNitric SDKNitric Runtime (plugin)Cloud DMBS (e.g. AWS RDS)

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 infrastructure modules, including both Terraform and Pulumi:

Last updated on Feb 15, 2025