Skip to content

Docker postgres config for NextJS template#422

Open
JoeOakhartNava wants to merge 2 commits into
mainfrom
docker-postgres-config
Open

Docker postgres config for NextJS template#422
JoeOakhartNava wants to merge 2 commits into
mainfrom
docker-postgres-config

Conversation

@JoeOakhartNava

@JoeOakhartNava JoeOakhartNava commented Dec 8, 2025

Copy link
Copy Markdown
Member

Ticket

Related to #267

Changes

Added docker config for Postgres

Context for reviewers

This does not add ORM or more complex DB integration to the NextJS template. The goal of this change is to create a better starting point for teams using this template that encourages them to favor a more reliable Postgres docker container over a less reliable Prisma implementation.

Testing

Created a new application from the revised template. Verified that it built the docker images and ran the application as expected out-of-the-box.

@doshitan doshitan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this does not cover the full scope of #267, let's not say "Resolves #267" which will close the issue, but "related to"/"part of"/etc

ports:
- 6006:6006

{{ app_name }}-database:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should follow a similar pattern as is established for the other templates:

(they are not quite normalized yet, but everything should eventually converge)

Which here looks like:

  • Drop the separate container file
  • Update the command
  • Drop the explicit network declaration

Given the Next.js template is often used to build client-side only apps, could also make the DB part conditional on a template variable, but I think we can cross that bridge later as it's easy enough to delete or comment out the DB block if you don't want it.

FROM postgres:latest

RUN rm -rf /var/lib/postgresql/data
COPY ./schema.sql /docker-entrypoint-initdb.d/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app template should provide a db-migrate script for setting up the database, like the other app templates, e.g. https://github.com/navapbc/template-application-rails/blob/7ac4e6636faefaf70add7cc166336960ade8fdf7/template/%7B%7Bapp_name%7D%7D/bin/db-migrate

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give me any more context on this? I used the separate Docker image for the DB because it seemed like the easiest way to pull in initial schema with a sql script. I see that the example you reference runs a Ruby tool called Rake for DB migration. NextJS doesn't have a direct equivalent. What would it look like to follow the pattern you describe without Ruby?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give me any more context on this?

See https://github.com/navapbc/template-infra/blob/ee6fe10f27716b9f434960052d86634dee85d6fe/template-only-docs/application-requirements.md?plain=1#L11

While it does not seem like we are looking to support a DB in hosted environments here, we should build towards the established patterns. Ideally this should be ensure the postgres client/libraries are available in the container environment, provide a init-db make target (rails, flask), etc. so there's a more completely supported workflow even locally. But that doesn't necessarily have to be done here.

What would it look like to follow the pattern you describe without Ruby?

It should be appropriate to the application framework. In this case if we don't have an actual DB library to use, we should use psql directly (see https://github.com/navapbc/template-infra/blob/ee6fe10f27716b9f434960052d86634dee85d6fe/template-only-app/db-migrate as a reference, though will need some slight adaptation to support the local development usecase).

Comment thread CONTRIBUTING.MD

If the issue is related to security, please email us directly at strata@navapbc.com

## Testing Changes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can drop this section. The current workflow suggested is still pretty much to develop in a template instance first, then backport to template. I think we'll want to centralize/coordinate doc updates across all the templates for updates to this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would a user who has pulled down template-application-nextjs know to look to the documentation you reference? I'm not seeing any guidance on the development process within template-application-nextjs, which creates a confusing situation for a developer who wants to contribute an update.

@doshitan doshitan Dec 9, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good question that needs a consistent (and somewhat centralized) answer across Strata templates. There's a variety of things that need to be pulled together, so let's avoid scattering info further for the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants