Skip to content
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6695eab
Started working Liquibase config
Glenruben Nov 7, 2025
89ab3ec
Merge branch 'develop' into MIM-2404-database-schema-migration-start
Glenruben Nov 13, 2025
7157451
Add prisma and make initial database introspection
Glenruben Nov 13, 2025
9e95a03
Rename all tables, update Prisma schema
Glenruben Nov 13, 2025
e2010af
Removed Vite btw
Glenruben Nov 13, 2025
03f2ce3
We won't be needing Liquibase config
Glenruben Nov 13, 2025
372e065
No need to include the postgres driver
Glenruben Nov 13, 2025
70c8651
add a first test, use node test runner with tsx
Glenruben Nov 13, 2025
9c0ed69
Package application with pkgroll
Glenruben Nov 14, 2025
62d3d57
Add PG schema to DB config and prisma schema
Glenruben Nov 14, 2025
6fd3e63
Rename database url from environment, matches Nais
Glenruben Nov 14, 2025
86329cf
Remove dev env variable
Glenruben Nov 14, 2025
0b2fdc9
No need for this init file, it was for Liquibase
Glenruben Nov 14, 2025
b9ffe29
Add persistence documentation
Glenruben Nov 14, 2025
9ac55ea
Documentation update
Glenruben Nov 14, 2025
59d2d86
Add .env and db config to docs
Glenruben Nov 14, 2025
80e2dca
Need to import config and ensure prisma connects to the database
Glenruben Nov 14, 2025
e6c1752
Remove generated prisma files.
Glenruben Nov 14, 2025
72689a9
refactor: translated variables for database
annesiri Nov 18, 2025
01531c4
Merge branch 'develop' into MIM-2404-database-schema-migration-start
Glenruben Nov 20, 2025
7c7fe48
Upgrade to latest, major, version of Prisma
Glenruben Nov 20, 2025
0c77dfc
Remove named schema, use public.
Glenruben Nov 21, 2025
679eed1
Fjern referanse til prisma dev
Glenruben Nov 21, 2025
090fcdd
Fjern utdatert folder fra gammel versjon av prisma
Glenruben Nov 21, 2025
fad7e63
Merge branch 'MIM-2404-translate-database-enities-to-english' into MI…
Glenruben Nov 21, 2025
6378d39
Add migration script for renamed fields and tables
Glenruben Nov 25, 2025
50786e0
Remove duplicate endpoint
Glenruben Nov 25, 2025
61700ac
Remove comment
Glenruben Nov 27, 2025
51bc192
Bumped package versions, including Prisma
Glenruben Nov 27, 2025
7240c9f
Clarify documentation for Prisma first run
Glenruben Nov 27, 2025
a0f4e50
Rename scema field and column detaljnivå
Glenruben Nov 27, 2025
13709b3
Override vulnerable packages from Prisma
Glenruben Nov 27, 2025
9dd505f
Move ignore declaration for eslint to new location for Prisma generat…
Glenruben Nov 27, 2025
d847405
Merge branch 'develop' into MIM-2404-database-schema-migration-start
Glenruben Nov 27, 2025
c2d6c94
Translate navn field, remove comment
Glenruben Nov 28, 2025
f359666
Add placeholder env for building
Glenruben Nov 28, 2025
ef7a982
Remove outdated comment
Glenruben Nov 28, 2025
0bc8221
Typo
Glenruben Nov 28, 2025
a16a79f
move env to job scope
Glenruben Nov 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions .github/workflows/testOnPr.js.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Build and test
on:
pull_request:
branches: [ "develop", "main" ]
branches: ["develop", "main"]
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -10,13 +10,14 @@ jobs:
node-version: [22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v5
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm run ci-test
- run: npm run lint
- uses: actions/checkout@v5
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run generate
- run: npm run build --if-present
- run: npm run ci-test
- run: npm run lint
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ node_modules

# Ignore coverage folder
coverage/

# Ignore generate folder, you should make your own.
# Use npm run generate
Comment thread
Glenruben marked this conversation as resolved.
src/generated/

# Do not commit your .env file, please
.env
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ RUN npm install
# Copy the application source code
COPY . .

# Generate the Prisma client libraries
RUN npm run generate
Comment thread
Glenruben marked this conversation as resolved.

# Build the application
RUN npm run build

Expand All @@ -25,5 +28,4 @@ EXPOSE 9000
EXPOSE 8080

# Command to start the application
# CMD [ "sh", "-c", "npm run db:deploy && npm run start" ]
CMD [ "sh", "-c", "npm run start" ]
CMD [ "sh", "-c", "npm run db:deploy && npm run start" ]
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Statreg API is a backend service for statistikkregisteret. It provides endpoints
## DEV
```
npm install
npm run generate
Comment thread
Glenruben marked this conversation as resolved.
npm run dev
```
Go to http://localhost:8080 to see results.
Expand Down Expand Up @@ -32,10 +33,10 @@ Help secure Express apps by setting HTTP response headers.
Express middleware with popular prometheus metrics in one bundle. Exposes `/metrics` endpoint.

## Docker
## Prerequisites
### Prerequisites
To get started, you first need to [install Colima and Docker CLI.](https://statistics-norway.atlassian.net/wiki/spaces/mimir/pages/4827381761/Bytte+fra+Docker+Desktop+til+Colima)

## Build and run
### Build and run
Start Colima with the default configuration
```bash
colima start
Expand All @@ -49,4 +50,23 @@ docker build -t ssbno/statreg-api .
Then, run
```bash
docker run -it -p 8080:8080 ssbno/statreg-api
```
```

## Persistence

### Database

We use PostgreSQL, provided by Nais in our live environments. Locally you can set up your own Postgres db in one of many ways - install PostgreSQL [from either the website](https://www.postgresql.org/download/), Homebrew or your package manager of choice. If you are on a mac, postgres.app is recommended and makes setup very easy and quick.

### Prisma

We use Prisma both as our ORM and as our schema migration tool in this project. We strongly recommend reading [this article](https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/evolve-your-schema-typescript-postgresql) before touching the schema if you have not used Prisma before.

In short though, Prisma handles schema changes with Migrations, which are incremental change sets applied to the database. Applied migrations are recorded in the database. Migrations are generated with the Prisma CLI, checked into the codebase and _never_ manually changed. After having made changes to your schema, you can push these changes to your local db with `npx prisma db push`. Note that this does not update your migrations, but you can do this as many times as you like until the desired state is achieved. (sidenote: this may cause data loss locally)

When you are happy with your updated schema, you can run `npx prisma migrate dev --name name-of-changeset`. This applies previous changes in schema, generates a new migration with the supplied name, applies all unapplied migrations and triggers generation of a new Prisma Client.

There are many fun pitfalls and ways of messing up both your local db and production data using prisma, so educate yourself, make sure you know what you are doing, and be ready to roll back changes.

For local development, we can use a file named ".env" located in the root directory of the project. Currently we only use one environment variable from this file - see prisma.config.ts - and it should look something like this:
`NAIS_DATABASE_MYAPP_MYDB_URL="postgresql://<USERNAME>@localhost:5432/statreg_db"`
Loading