diff --git a/.github/workflows/_deploy-reusable.yaml b/.github/workflows/_deploy-reusable.yaml index de74859f..a130c23b 100644 --- a/.github/workflows/_deploy-reusable.yaml +++ b/.github/workflows/_deploy-reusable.yaml @@ -59,7 +59,9 @@ jobs: env: APP_DB_URL: ${{ secrets.APP_DB_URL }} APP_DB_AUTH_TOKEN: ${{ secrets.APP_DB_AUTH_TOKEN }} - run: pnpm db:update + run: | + pnpm db:setup + pnpm db:update - name: Build app env: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 212dd243..e4ed5ed6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -29,5 +29,7 @@ jobs: - name: Install Dependencies run: pnpm i - - name: Update and Test database - run: pnpm db:update:catdat + - name: Test database + run: | + pnpm db:setup:catdat + pnpm db:update diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4e2a70bb..bde14875 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,8 +48,9 @@ You need to have [Git](https://git-scm.com/), [NodeJS](https://nodejs.org/) and 3. Change into the directory with `cd CatDat`. 4. Install dependencies with `pnpm install`. 5. Create a local `.env` file from `.env.example`. -6. Create the local database with `pnpm db:update`. -7. Start the local development server with `pnpm dev`. +6. Create the local database with `pnpm db:setup`. +7. Update the local database with `pnpm db:update`. +8. Start the local development server with `pnpm dev`. **For Maintainers:** Redis is required for admin features and submissions. Start a local instance on port 6379 via `redis-server --port 6379`. @@ -73,7 +74,7 @@ to continuously run this update when a file in the subfolder [/databases/catdat/ ### Troubleshooting -- If the local database is corrupted, recreate it using `pnpm db:update`. +- If the local database is corrupted, or its schema has changed, recreate it using `pnpm db:setup`. - If the `pnpm db:update` command fails, examine the error message to determine the cause. It could be due to malformed SQL, a contradictory property, or a failing test in the `pnpm db:test` script (which also runs as part of the update command), as explained below. ### Tests for Data Quality diff --git a/DATABASE.md b/DATABASE.md index a51ccbae..792b5c9b 100644 --- a/DATABASE.md +++ b/DATABASE.md @@ -44,7 +44,7 @@ For functors there are similar tables, such as: ## Schema vs. Data -The schema defines the structure of the database: tables, views, indexes, and triggers. It is specified in several SQL files located in the subfolder [/databases/catdat/schema](/databases/catdat/schema/). The command `pnpm db:setup` deletes the old database file (if it exists) and creates a new one using this schema. +The schema defines the structure of the database: tables, views, indexes, and triggers. It is specified in several SQL files located in the subfolder [/databases/catdat/schema](/databases/catdat/schema/). The command `pnpm db:setup` deletes the old database file (if it exists) and creates a new one using this schema. This is required when the schema changes, so it is recommended to run it periodically. Database entries (categories, properties, implications, etc.) are defined in SQL files located in the subfolder [/databases/catdat/data](/databases/catdat/data/). The command `pnpm db:seed` replaces the current contents of the database by clearing all existing data and inserting the entries defined in these SQL files. @@ -60,7 +60,7 @@ The command `pnpm db:test` executes some tests and verifies that the data behave ## One command for everything -Use `pnpm db:update` to run all the commands in sequence: `pnpm db:setup`, `pnpm db:seed`,`pnpm db:deduce`, and `pnpm db:test`. +Use `pnpm db:update` to run all the commands in sequence: `pnpm db:seed`,`pnpm db:deduce`, and `pnpm db:test`. Use `pnpm db:watch` to run this command automatically every time a file in the subfolder [/databases/catdat/data](/databases/catdat/data) changes. This is useful in particular during development. diff --git a/README.md b/README.md index 2d930930..964e44c2 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,9 @@ You need to have [Git](https://git-scm.com/), [NodeJS](https://nodejs.org/) and 3. Change into the directory with `cd CatDat`. 4. Install dependencies with `pnpm install`. 5. Create a local `.env` file from `.env.example`. -6. Create the local database with `pnpm db:update`. -7. Start the local development server with `pnpm dev`. +6. Create the local database with `pnpm db:setup`. +7. Update the local database with `pnpm db:update`. +8. Start the local development server with `pnpm dev`. **For Maintainers:** Redis is required for admin features and submissions. Start a local instance on port 6379 via `redis-server --port 6379`. diff --git a/package.json b/package.json index 2c8f9e2f..ded647ee 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,8 @@ "db:deduce": "tsx databases/catdat/scripts/deduce.ts", "db:test": "tsx databases/catdat/scripts/test.ts", "db:snapshot": "cp databases/catdat/catdat.db static/databases/catdat-snapshot.db", - "db:update": "pnpm db:setup && pnpm db:seed && pnpm db:deduce && pnpm db:test && pnpm db:snapshot", - "db:watch": "tsx databases/catdat/scripts/watch.ts", - "db:update:catdat": "pnpm db:setup:catdat && pnpm db:seed && pnpm db:deduce && pnpm db:test && pnpm db:snapshot" + "db:update": "pnpm db:seed && pnpm db:deduce && pnpm db:test && pnpm db:snapshot", + "db:watch": "tsx databases/catdat/scripts/watch.ts" }, "devDependencies": { "@sveltejs/adapter-netlify": "^6.0.4",