namespace: Radius.Data
types:
  postgreSqlDatabases:  
    description: |
      The Radius.Data/postgreSqlDatabases Resource Type deploys a PostgreSQL database. To deploy a new PostgreSQL database, add the postgreSqlDatabases resource to the application definition Bicep file.
      
      ```
      extension radius
      param environment string 

      resource database 'Radius.Data/postgreSqlDatabases@2025-08-01-preview' = {
        name: 'database'
        properties: {
          application: myApplication.id
          environment: environment
        }
      }
      ```

      To connect your container to the database, create a connection from the Container resource to the database as shown below. 
      ```
      resource myApplication 'Applications.Core/Applications@2023-10-01-preview' = { ... }

      resource frontend 'Applications.Core/containers@2023-10-01-preview' = {
        name: 'frontend'
        properties: {
          application: myApplication.id
          environment: environment
          container: {
            image: 'frontend:1.25'
            ports: {
              web: {
                containerPort: 8080
              }
            }
          }
          connections: {
            postgresql: {
              source: database.id
            }
          }
        }
      }
      ```

      The connection automatically injects environment variables into the container for all properties from the database. The environment variables are named `CONNECTION_<CONNECTION-NAME>_<PROPERTY-NAME>`. In this example, the connection name is `postgresql` so the environment variables will be:
 
      - CONNECTION_POSTGRESQL_DATABASE
      - CONNECTION_POSTGRESQL_USERNAME
      - CONNECTION_POSTGRESQL_PASSWORD
      - CONNECTION_POSTGRESQL_HOST
      - CONNECTION_POSTGRESQL_PORT
    apiVersions:
      '2025-08-01-preview':
        schema: 
          type: object
          properties:
            environment:
              type: string
              description: "(Required) The Radius Environment ID. Typically set by the rad CLI. Typically value should be `environment`."
            application:
              type: string
              description: "(Optional) The Radius Application ID. `myApplication.id` for example."
            size:
              type: string
              enum: ['S', 'M', 'L']
              description: "(Optional) The size of the PostgreSQL database."
            database:
              type: string
              description: The name of the database.
              readOnly: true
            host:
              type: string
              description: The host name used to connect to the database.
              readOnly: true
            port:
              type: string
              description: The port number used to connect to the database.
              readOnly: true
            username:
              type: string
              description: The username for connecting to the database.
              readOnly: true
            password:
              type: string
              description: The password for connecting to the database.
              readOnly: true
          required: [environment]