Skip to content

Commit e4e48c1

Browse files
committed
remove migrations table, use schema files instead
1 parent 2915ba4 commit e4e48c1

21 files changed

Lines changed: 55 additions & 127 deletions

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ to continuously run this update when a file in the subfolder [/databases/catdat/
6969

7070
### Troubleshooting
7171

72-
- If the local database is corrupted, delete the `catdat.db` file and recreate it using `pnpm db:update`.
72+
- If the local database is corrupted, recreate it using `pnpm db:update`.
7373
- 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.
7474

7575
### Tests for Data Quality

DATABASE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ For functors there are similar tables, such as:
4242
- `functor_implications`
4343
- `functor_property_assignments`
4444

45-
## Migrations vs. Data
45+
## Schema vs. Data
4646

47-
Migrations update the database structure: tables, views, indexes, and triggers. They are defined in SQL files located in the subfolder [/databases/catdat/migrations](/databases/catdat/migrations/). The command `pnpm db:migrate` applies any new migrations.
47+
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.
4848

49-
Database entries (categories, properties, implications, etc.) are defined via SQL files in the subfolder [/databases/catdat/data](/databases/catdat/data). The command `pnpm db:seed` replaces the current database by clearing all existing data and inserting the entries defined in these SQL files.
49+
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.
5050

5151
## Derived Data
5252

@@ -60,7 +60,7 @@ The command `pnpm db:test` executes some tests and verifies that the data behave
6060

6161
## One command for everything
6262

63-
Use `pnpm db:update` to run all the commands in sequence: `pnpm db:migrate`, `pnpm db:seed`,`pnpm db:deduce`, and `pnpm db:test`.
63+
Use `pnpm db:update` to run all the commands in sequence: `pnpm db:setup`, `pnpm db:seed`,`pnpm db:deduce`, and `pnpm db:test`.
6464

6565
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.
6666

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ const db = createClient({
1313
authToken: APP_DB_AUTH_TOKEN,
1414
})
1515

16-
migrate()
16+
setup()
1717

1818
/**
1919
* Creates the tables in the app database.
2020
*/
21-
async function migrate() {
22-
console.info('\n--- Migrate App database ---')
21+
async function setup() {
22+
console.info('\n--- Setup App database ---')
2323
await create_visits_table()
2424
await create_submissions_table()
2525
}

databases/catdat/migrations/014_order_assignments.sql

Lines changed: 0 additions & 35 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

databases/catdat/migrations/004_category-properties.sql renamed to databases/catdat/schema/004_category-properties.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ CREATE TABLE related_category_properties (
2020
);
2121

2222
CREATE TABLE category_property_assignments (
23+
id INTEGER PRIMARY KEY,
2324
category_id TEXT NOT NULL,
2425
property_id TEXT NOT NULL,
2526
is_satisfied INTEGER NOT NULL
2627
CHECK (is_satisfied in (TRUE, FALSE)),
2728
reason TEXT NOT NULL CHECK (length(reason) > 0),
2829
is_deduced INTEGER NOT NULL DEFAULT FALSE
2930
CHECK (is_deduced in (TRUE, FALSE)),
30-
position INTEGER NOT NULL DEFAULT 0,
31-
PRIMARY KEY (category_id, property_id),
31+
UNIQUE (category_id, property_id),
3232
FOREIGN KEY (category_id) REFERENCES categories (id) ON DELETE CASCADE,
3333
FOREIGN KEY (property_id) REFERENCES category_properties (id) ON DELETE CASCADE
3434
);

databases/catdat/migrations/005_category-implications.sql renamed to databases/catdat/schema/005_category-implications.sql

File renamed without changes.

databases/catdat/migrations/006_category-implications-view.sql renamed to databases/catdat/schema/006_category-implications-view.sql

File renamed without changes.

0 commit comments

Comments
 (0)