|
217 | 217 | - password
|
218 | 218 |
|
219 | 219 |
|
220 |
| -- uri: template://default-provisioners/postgres |
221 |
| - # By default, match all redis types regardless of class and id. If you want to override this, create another |
222 |
| - # provisioner definition with a higher priority. |
| 220 | +- uri: template://default-provisioners/postgres-instance |
| 221 | + |
223 | 222 | type: postgres-instance
|
224 |
| - description: Provisions a dedicated database on a shared postgres instance |
| 223 | + description: Provisions a dedicated Postgres instance |
225 | 224 | # Init template has the random service name and password if needed later
|
226 | 225 | init: |
|
227 | 226 | randomServiceName: pg-{{ randAlphaNum 6 }}
|
|
232 | 231 | publishPort: {{ dig "annotations" "compose.score.dev/publish-port" "0" .Metadata | quote }}
|
233 | 232 | # The state for each database resource is a unique db name and credentials
|
234 | 233 | state: |
|
235 |
| - database: {{ dig "database" .Init.randomDatabase .State | quote }} |
236 |
| - username: {{ dig "username" .Init.randomUsername .State | quote }} |
| 234 | + database: "postgres" |
| 235 | + username: "postgres" |
237 | 236 | password: {{ dig "password" .Init.randomPassword .State | quote }}
|
238 | 237 | # The outputs are the core database outputs. We output both name and database for broader compatibility.
|
239 | 238 | outputs: |
|
240 | 239 | host: {{ dig .Init.sk "instanceServiceName" "" .Shared }}
|
241 | 240 | port: 5432
|
242 |
| - username: {{ .State.username }} |
243 |
| - password: {{ .State.password }} |
244 |
| - # Write out an idempotent create script per database |
245 |
| - files: | |
246 |
| - {{ dig .Init.sk "instanceServiceName" "" .Shared }}-db-scripts/{{ .State.database }}.sql: | |
247 |
| - SELECT 'CREATE DATABASE "{{ .State.database }}"' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '{{ .State.database }}')\gexec |
248 |
| - SELECT $$CREATE USER "{{ .State.username }}" WITH PASSWORD '{{ .State.password }}'$$ WHERE NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '{{ .State.username }}')\gexec |
249 |
| - GRANT ALL PRIVILEGES ON DATABASE "{{ .State.database }}" TO "{{ .State.username }}"; |
250 |
| - \connect "{{ .State.database }}"; |
251 |
| - GRANT ALL ON SCHEMA public TO "{{ .State.username }}"; |
| 241 | + username: postgres |
| 242 | + password: {{ dig .Init.sk "instancePassword" "" .Shared }} |
252 | 243 | # Ensure the data volume exists
|
253 | 244 | volumes: |
|
254 | 245 | {{ dig .Init.sk "instanceServiceName" "" .Shared }}-data:
|
|
272 | 263 | target: /var/lib/postgresql/data
|
273 | 264 | healthcheck:
|
274 | 265 | test: ["CMD", "pg_isready", "-U", "postgres"]
|
275 |
| - interval: 2s |
276 |
| - timeout: 2s |
277 |
| - retries: 15 |
278 |
| - {{ dig .Init.sk "instanceServiceName" "" .Shared }}-init: |
279 | 266 | image: mirror.gcr.io/postgres:17-alpine
|
280 | 267 | entrypoint: ["/bin/sh"]
|
281 | 268 | environment:
|
|
0 commit comments