diff --git a/README.md b/README.md index 7176a90c6..4e70c96be 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,14 @@ Then run: docker run --rm -it -v "$PWD":/app -w /app node:18 /bin/bash +### connecting to the mySQL server +If you are not planning to alter the database. Connecting to the PlanetScale development database is the easiest option. + +Add `DATABASE_URL` environment variable the file `apps/researcher/.env.local` + +If you want to test migration, you need a local database. You can read more about this in the [object-lists readme](packages/object-lists/README.md). + + ### Install packages docker run --rm -it -v "$PWD":/app -w /app node:18 npm install --no-progress diff --git a/package-lock.json b/package-lock.json index f2d32241e..08fafaa1f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3327,12 +3327,10 @@ } }, "node_modules/@drizzle-team/studio": { - "version": "0.0.5", - "dev": true + "version": "0.0.5" }, "node_modules/@esbuild-kit/core-utils": { "version": "3.2.2", - "dev": true, "license": "MIT", "dependencies": { "esbuild": "~0.18.20", @@ -3341,7 +3339,6 @@ }, "node_modules/@esbuild-kit/core-utils/node_modules/source-map": { "version": "0.6.1", - "dev": true, "license": "BSD-3-Clause", "engines": { "node": ">=0.10.0" @@ -3349,7 +3346,6 @@ }, "node_modules/@esbuild-kit/core-utils/node_modules/source-map-support": { "version": "0.5.21", - "dev": true, "license": "MIT", "dependencies": { "buffer-from": "^1.0.0", @@ -3358,7 +3354,6 @@ }, "node_modules/@esbuild-kit/esm-loader": { "version": "2.5.5", - "dev": true, "license": "MIT", "dependencies": { "@esbuild-kit/core-utils": "^3.0.0", @@ -3370,7 +3365,6 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ @@ -4066,6 +4060,66 @@ } } }, + "node_modules/@next/swc-darwin-arm64": { + "version": "13.4.7", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.4.7.tgz", + "integrity": "sha512-VZTxPv1b59KGiv/pZHTO5Gbsdeoxcj2rU2cqJu03btMhHpn3vwzEK0gUSVC/XW96aeGO67X+cMahhwHzef24/w==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-darwin-x64": { + "version": "13.4.7", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.4.7.tgz", + "integrity": "sha512-gO2bw+2Ymmga+QYujjvDz9955xvYGrWofmxTq7m70b9pDPvl7aDFABJOZ2a8SRCuSNB5mXU8eTOmVVwyp/nAew==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-gnu": { + "version": "13.4.7", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.4.7.tgz", + "integrity": "sha512-6cqp3vf1eHxjIDhEOc7Mh/s8z1cwc/l5B6ZNkOofmZVyu1zsbEM5Hmx64s12Rd9AYgGoiCz4OJ4M/oRnkE16/Q==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-musl": { + "version": "13.4.7", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.4.7.tgz", + "integrity": "sha512-T1kD2FWOEy5WPidOn1si0rYmWORNch4a/NR52Ghyp4q7KyxOCuiOfZzyhVC5tsLIBDH3+cNdB5DkD9afpNDaOw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/@next/swc-linux-x64-gnu": { "version": "13.4.7", "cpu": [ @@ -4094,6 +4148,51 @@ "node": ">= 10" } }, + "node_modules/@next/swc-win32-arm64-msvc": { + "version": "13.4.7", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.4.7.tgz", + "integrity": "sha512-NPnmnV+vEIxnu6SUvjnuaWRglZzw4ox5n/MQTxeUhb5iwVWFedolPFebMNwgrWu4AELwvTdGtWjqof53AiWHcw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-ia32-msvc": { + "version": "13.4.7", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.4.7.tgz", + "integrity": "sha512-6Hxijm6/a8XqLQpOOf/XuwWRhcuc/g4rBB2oxjgCMuV9Xlr2bLs5+lXyh8w9YbAUMYR3iC9mgOlXbHa79elmXw==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-x64-msvc": { + "version": "13.4.7", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.4.7.tgz", + "integrity": "sha512-sW9Yt36Db1nXJL+mTr2Wo0y+VkPWeYhygvcHj1FF0srVtV+VoDjxleKtny21QHaG05zdeZnw2fCtf2+dEqgwqA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "license": "MIT", @@ -5614,7 +5713,6 @@ }, "node_modules/buffer-from": { "version": "1.1.2", - "dev": true, "license": "MIT" }, "node_modules/bundle-name": { @@ -5815,7 +5913,6 @@ }, "node_modules/cli-color": { "version": "2.0.3", - "dev": true, "license": "ISC", "dependencies": { "d": "^1.0.1", @@ -6242,7 +6339,6 @@ }, "node_modules/d": { "version": "1.0.1", - "dev": true, "license": "ISC", "dependencies": { "es5-ext": "^0.10.50", @@ -6575,7 +6671,6 @@ }, "node_modules/difflib": { "version": "0.2.4", - "dev": true, "dependencies": { "heap": ">= 0.2.0" } @@ -6693,7 +6788,6 @@ }, "node_modules/dreamopt": { "version": "0.8.0", - "dev": true, "dependencies": { "wordwrap": ">=0.0.2" }, @@ -6703,7 +6797,6 @@ }, "node_modules/drizzle-kit": { "version": "0.19.13", - "dev": true, "license": "MIT", "dependencies": { "@drizzle-team/studio": "^0.0.5", @@ -6725,7 +6818,6 @@ }, "node_modules/drizzle-kit/node_modules/brace-expansion": { "version": "2.0.1", - "dev": true, "license": "MIT", "dependencies": { "balanced-match": "^1.0.0" @@ -6733,7 +6825,6 @@ }, "node_modules/drizzle-kit/node_modules/camelcase": { "version": "7.0.1", - "dev": true, "license": "MIT", "engines": { "node": ">=14.16" @@ -6744,7 +6835,6 @@ }, "node_modules/drizzle-kit/node_modules/chalk": { "version": "5.3.0", - "dev": true, "license": "MIT", "engines": { "node": "^12.17.0 || ^14.13 || >=16.0.0" @@ -6755,7 +6845,6 @@ }, "node_modules/drizzle-kit/node_modules/commander": { "version": "9.5.0", - "dev": true, "license": "MIT", "engines": { "node": "^12.20.0 || >=14" @@ -6763,7 +6852,6 @@ }, "node_modules/drizzle-kit/node_modules/glob": { "version": "8.1.0", - "dev": true, "license": "ISC", "dependencies": { "fs.realpath": "^1.0.0", @@ -6781,7 +6869,6 @@ }, "node_modules/drizzle-kit/node_modules/glob/node_modules/minimatch": { "version": "5.1.6", - "dev": true, "license": "ISC", "dependencies": { "brace-expansion": "^2.0.1" @@ -6792,7 +6879,6 @@ }, "node_modules/drizzle-kit/node_modules/minimatch": { "version": "7.4.6", - "dev": true, "license": "ISC", "dependencies": { "brace-expansion": "^2.0.1" @@ -7121,7 +7207,6 @@ }, "node_modules/es5-ext": { "version": "0.10.62", - "dev": true, "hasInstallScript": true, "license": "ISC", "dependencies": { @@ -7135,7 +7220,6 @@ }, "node_modules/es6-iterator": { "version": "2.0.3", - "dev": true, "license": "MIT", "dependencies": { "d": "1", @@ -7145,7 +7229,6 @@ }, "node_modules/es6-symbol": { "version": "3.1.3", - "dev": true, "license": "ISC", "dependencies": { "d": "^1.0.1", @@ -7154,7 +7237,6 @@ }, "node_modules/es6-weak-map": { "version": "2.0.3", - "dev": true, "license": "ISC", "dependencies": { "d": "1", @@ -7165,7 +7247,6 @@ }, "node_modules/esbuild": { "version": "0.18.20", - "dev": true, "hasInstallScript": true, "license": "MIT", "bin": { @@ -7201,7 +7282,6 @@ }, "node_modules/esbuild-register": { "version": "3.4.2", - "dev": true, "license": "MIT", "dependencies": { "debug": "^4.3.4" @@ -8036,7 +8116,6 @@ }, "node_modules/event-emitter": { "version": "0.3.5", - "dev": true, "license": "MIT", "dependencies": { "d": "1", @@ -8119,7 +8198,6 @@ }, "node_modules/ext": { "version": "1.7.0", - "dev": true, "license": "ISC", "dependencies": { "type": "^2.7.2" @@ -8127,7 +8205,6 @@ }, "node_modules/ext/node_modules/type": { "version": "2.7.2", - "dev": true, "license": "ISC" }, "node_modules/extend": { @@ -8508,7 +8585,6 @@ }, "node_modules/get-tsconfig": { "version": "4.5.0", - "dev": true, "license": "MIT", "funding": { "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" @@ -8882,7 +8958,6 @@ }, "node_modules/hanji": { "version": "0.0.5", - "dev": true, "license": "ISC", "dependencies": { "lodash.throttle": "^4.1.1", @@ -8975,7 +9050,6 @@ }, "node_modules/heap": { "version": "0.2.7", - "dev": true, "license": "MIT" }, "node_modules/hosted-git-info": { @@ -9535,7 +9609,6 @@ }, "node_modules/is-promise": { "version": "2.2.2", - "dev": true, "license": "MIT" }, "node_modules/is-property": { @@ -10781,7 +10854,6 @@ }, "node_modules/json-diff": { "version": "0.9.0", - "dev": true, "license": "MIT", "dependencies": { "cli-color": "^2.0.0", @@ -11114,7 +11186,6 @@ }, "node_modules/lodash.throttle": { "version": "4.1.1", - "dev": true, "license": "MIT" }, "node_modules/log-symbols": { @@ -11213,7 +11284,6 @@ }, "node_modules/lru-queue": { "version": "0.1.0", - "dev": true, "license": "MIT", "dependencies": { "es5-ext": "~0.10.2" @@ -11273,7 +11343,6 @@ }, "node_modules/memoizee": { "version": "0.4.15", - "dev": true, "license": "ISC", "dependencies": { "d": "^1.0.1", @@ -11625,7 +11694,6 @@ }, "node_modules/next-tick": { "version": "1.1.0", - "dev": true, "license": "ISC" }, "node_modules/next/node_modules/postcss": { @@ -13294,7 +13362,6 @@ }, "node_modules/sisteransi": { "version": "1.0.5", - "dev": true, "license": "MIT" }, "node_modules/slash": { @@ -14001,7 +14068,6 @@ }, "node_modules/timers-ext": { "version": "0.1.7", - "dev": true, "license": "ISC", "dependencies": { "es5-ext": "~0.10.46", @@ -14270,7 +14336,6 @@ }, "node_modules/type": { "version": "1.2.0", - "dev": true, "license": "ISC" }, "node_modules/type-check": { @@ -14781,7 +14846,6 @@ }, "node_modules/wordwrap": { "version": "1.0.0", - "dev": true, "license": "MIT" }, "node_modules/wrap-ansi": { @@ -15059,19 +15123,18 @@ "name": "@colonial-collections/object-lists", "version": "0.0.0", "dependencies": { + "dotenv": "16.3.1", + "drizzle-kit": "0.19.13", "drizzle-orm": "0.28.5", "mysql2": "3.6.0" }, "devDependencies": { - "dotenv": "16.3.1", - "drizzle-kit": "0.19.13", "eslint-config-custom": "*", "tsconfig": "*" } }, "packages/object-lists/node_modules/dotenv": { "version": "16.3.1", - "dev": true, "license": "BSD-2-Clause", "engines": { "node": ">=12" diff --git a/packages/object-lists/README.md b/packages/object-lists/README.md new file mode 100644 index 000000000..9f05b95d4 --- /dev/null +++ b/packages/object-lists/README.md @@ -0,0 +1,38 @@ +# Object Lists + +This package is the database connector needed to read and write object lists. To connect to the database via the researcher app, ensure the environment variable DATABASE_URL is set in `apps/researcher/.env.local`. If you want to connect to the database outside the app to run scripts, add the DATABASE_URL to `packages/object-lists/.env.local`. + +# Option 1: Connecting with PlanetScale + +If you are not planning to alter the database. Connecting to the PlanetScale development database is the easiest option. You can find the needed DATABASE_URL in Vercel. + +# Option 2: Connecting with a local MySQL database (docker). + +You can create a MySQL database with docker if you prefer using a local database. For example, if you want to test migrations. Use the following command to start your MySQL container. It will create a new Docker volume called MySQL. + + docker run --name mysql -d \ + -p 3306:3306 \ + -e MYSQL_ROOT_PASSWORD=change-me \ + -v mysql:/var/lib/mysql \ + mysql:8 + +More commands can be found in the helpful blog [How to Use Docker for Your MySQL Database](https://earthly.dev/blog/docker-mysql/). + +Create a new database with: + + docker exec -it mysql mysql -p + mysql> CREATE DATABASE local_database_name + +Set the DATABASE_URL to: + + DATABASE_URL='mysql://root:{password}@localhost:3306/{database_name}' + +# Schema updates + +Whenever you apply changes to the schema, you need to run `npm run db:generate`, which will generate SQL migration for you. + +To push the changes to your local database, run `npm run db:push`. + +# Drizzle Studio + +With Drizzle Studio, you can explore the SQL database. Depending on the DATABASE_URL, you can explore both local and PlanetScale databases. Open Drizzle Studio with `npm run db:studio -w object-lists`. diff --git a/packages/object-lists/drizzle.config.ts b/packages/object-lists/drizzle.config.ts index 3bb86c17d..5e21e12c3 100644 --- a/packages/object-lists/drizzle.config.ts +++ b/packages/object-lists/drizzle.config.ts @@ -1,4 +1,3 @@ -/* eslint-disable node/no-unpublished-import */ import type {Config} from 'drizzle-kit'; import * as dotenv from 'dotenv'; diff --git a/packages/object-lists/package.json b/packages/object-lists/package.json index b905650ee..7b5027655 100644 --- a/packages/object-lists/package.json +++ b/packages/object-lists/package.json @@ -8,15 +8,15 @@ "db:generate": "drizzle-kit generate:mysql", "db:push": "drizzle-kit push:mysql", "db:drop": "drizzle-kit drop", - "db:studio": "dotenv -e ../../.env.local drizzle-kit studio" + "db:studio": "drizzle-kit studio" }, "devDependencies": { - "dotenv": "16.3.1", - "drizzle-kit": "0.19.13", "eslint-config-custom": "*", "tsconfig": "*" }, "dependencies": { + "dotenv": "16.3.1", + "drizzle-kit": "0.19.13", "drizzle-orm": "0.28.5", "mysql2": "3.6.0" }