From 193d45ab64372937a193bbd3385a3152a41f4e09 Mon Sep 17 00:00:00 2001 From: Hawken Rives Date: Mon, 20 May 2024 19:17:55 -0400 Subject: [PATCH 01/14] add initial content and workflows --- .github/workflows/database-tests.yml | 23 + .github/workflows/edge-function-tests.yml | 15 + .github/workflows/generate-types.yml | 22 + README.md | 8 + package-lock.json | 804 +++++++++++++++++++ package.json | 16 + supabase/.gitignore | 4 + supabase/config.toml | 171 ++++ supabase/seed.sql | 0 supabase/tests/database/hello_world.test.sql | 12 + 10 files changed, 1075 insertions(+) create mode 100644 .github/workflows/database-tests.yml create mode 100644 .github/workflows/edge-function-tests.yml create mode 100644 .github/workflows/generate-types.yml create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 supabase/.gitignore create mode 100644 supabase/config.toml create mode 100644 supabase/seed.sql create mode 100644 supabase/tests/database/hello_world.test.sql diff --git a/.github/workflows/database-tests.yml b/.github/workflows/database-tests.yml new file mode 100644 index 0000000..a4d26fc --- /dev/null +++ b/.github/workflows/database-tests.yml @@ -0,0 +1,23 @@ +name: 'database-tests' +on: + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: supabase/setup-cli@v1 + with: + version: latest + - run: supabase db lint + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: supabase/setup-cli@v1 + with: + version: latest + - run: supabase db start + - run: supabase test db diff --git a/.github/workflows/edge-function-tests.yml b/.github/workflows/edge-function-tests.yml new file mode 100644 index 0000000..ff035e3 --- /dev/null +++ b/.github/workflows/edge-function-tests.yml @@ -0,0 +1,15 @@ +name: 'edge-function-tests' +# on: +# pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: supabase/setup-cli@v1 + with: + version: 1.11.4 + - run: supabase start + - run: supabase functions serve + - run: deno test --allow-all deno-test.ts --env-file .env.local diff --git a/.github/workflows/generate-types.yml b/.github/workflows/generate-types.yml new file mode 100644 index 0000000..b7a5699 --- /dev/null +++ b/.github/workflows/generate-types.yml @@ -0,0 +1,22 @@ +name: 'generate-types' +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: supabase/setup-cli@v1 + with: + version: latest + - run: supabase init + - run: supabase db start + - name: Verify generated types match Postgres schema + run: | + supabase gen types typescript --local > schema.gen.ts + if ! git diff --ignore-space-at-eol --exit-code --quiet schema.gen.ts; then + echo "Detected uncommitted changes after build. See status below:" + git diff + exit 1 + fi diff --git a/README.md b/README.md index 2265377..5b521eb 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # ccc-databased approximate caution, approximate context + +## Getting Started + +```sh +$ npm install +$ npx supabase login +$ npx supabase start +``` diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..26ea404 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,804 @@ +{ + "name": "ccc-databased", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "ccc-databased", + "version": "1.0.0", + "license": "AGPL-3", + "devDependencies": { + "supabase": "^1.167.4" + } + }, + "node_modules/@isaacs/cliui": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", + "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dev": true, + "dependencies": { + "string-width": "^5.1.2", + "string-width-cjs": "npm:string-width@^4.2.0", + "strip-ansi": "^7.0.1", + "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", + "wrap-ansi": "^8.1.0", + "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@isaacs/fs-minipass": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@isaacs/fs-minipass/-/fs-minipass-4.0.1.tgz", + "integrity": "sha512-wgm9Ehl2jpeqP3zw/7mo3kRHFp5MEDhqAdwy1fTGkHAwnkGOVsgpvQhL8B5n1qlb01jV3n/bI0ZfZp5lWA1k4w==", + "dev": true, + "dependencies": { + "minipass": "^7.0.4" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/@pkgjs/parseargs": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", + "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", + "dev": true, + "optional": true, + "engines": { + "node": ">=14" + } + }, + "node_modules/agent-base": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", + "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "dev": true, + "dependencies": { + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true + }, + "node_modules/bin-links": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/bin-links/-/bin-links-4.0.4.tgz", + "integrity": "sha512-cMtq4W5ZsEwcutJrVId+a/tjt8GSbS+h0oNkdl6+6rBuEv8Ot33Bevj5KPm40t309zuhVic8NjpuL42QCiJWWA==", + "dev": true, + "dependencies": { + "cmd-shim": "^6.0.0", + "npm-normalize-package-bin": "^3.0.0", + "read-cmd-shim": "^4.0.0", + "write-file-atomic": "^5.0.0" + }, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/chownr": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-3.0.0.tgz", + "integrity": "sha512-+IxzY9BZOQd/XuYPRmrvEVjF/nqj5kgT4kEq7VofrDoM1MxoRjEWkrCC3EtLi59TVawxTAn+orJwFQcrqEN1+g==", + "dev": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/cmd-shim": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/cmd-shim/-/cmd-shim-6.0.3.tgz", + "integrity": "sha512-FMabTRlc5t5zjdenF6mS0MBeFZm0XqHqeOkcskKFb/LYCcRQ5fVgLOHVc4Lq9CqABd9zhjwPjMBCJvMCziSVtA==", + "dev": true, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dev": true, + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "dev": true, + "engines": { + "node": ">= 12" + } + }, + "node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/eastasianwidth": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dev": true + }, + "node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true + }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, + "node_modules/foreground-child": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", + "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.0", + "signal-exit": "^4.0.1" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "dev": true, + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/glob": { + "version": "10.3.15", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.15.tgz", + "integrity": "sha512-0c6RlJt1TICLyvJYIApxb8GsXoai0KUP7AxKKAtsYXdgJR1mGEUa7DgwShbdk1nly0PYoZj01xd4hzbq3fsjpw==", + "dev": true, + "dependencies": { + "foreground-child": "^3.1.0", + "jackspeak": "^2.3.6", + "minimatch": "^9.0.1", + "minipass": "^7.0.4", + "path-scurry": "^1.11.0" + }, + "bin": { + "glob": "dist/esm/bin.mjs" + }, + "engines": { + "node": ">=16 || 14 >=14.18" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/https-proxy-agent": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.4.tgz", + "integrity": "sha512-wlwpilI7YdjSkWaQ/7omYBMTliDcmCN8OLihO6I9B86g06lMyAoqgoDpV0XqoaPOKj+0DIdAvnsWfyAAhmimcg==", + "dev": true, + "dependencies": { + "agent-base": "^7.0.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", + "dev": true, + "engines": { + "node": ">=0.8.19" + } + }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true + }, + "node_modules/jackspeak": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.3.6.tgz", + "integrity": "sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==", + "dev": true, + "dependencies": { + "@isaacs/cliui": "^8.0.2" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + }, + "optionalDependencies": { + "@pkgjs/parseargs": "^0.11.0" + } + }, + "node_modules/lru-cache": { + "version": "10.2.2", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.2.tgz", + "integrity": "sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ==", + "dev": true, + "engines": { + "node": "14 || >=16.14" + } + }, + "node_modules/minimatch": { + "version": "9.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", + "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/minipass": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.1.tgz", + "integrity": "sha512-UZ7eQ+h8ywIRAW1hIEl2AqdwzJucU/Kp59+8kkZeSvafXhZjul247BvIJjEVFVeON6d7lM46XX1HXCduKAS8VA==", + "dev": true, + "engines": { + "node": ">=16 || 14 >=14.17" + } + }, + "node_modules/minizlib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-3.0.1.tgz", + "integrity": "sha512-umcy022ILvb5/3Djuu8LWeqUa8D68JaBzlttKeMWen48SjabqS3iY5w/vzeMzMUNhLDifyhbOwKDSznB1vvrwg==", + "dev": true, + "dependencies": { + "minipass": "^7.0.4", + "rimraf": "^5.0.5" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/mkdirp": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz", + "integrity": "sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==", + "dev": true, + "bin": { + "mkdirp": "dist/cjs/src/bin.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "dev": true, + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, + "node_modules/npm-normalize-package-bin": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-3.0.1.tgz", + "integrity": "sha512-dMxCf+zZ+3zeQZXKxmyuCKlIDPGuv8EF940xbkC4kQVDTtqoh6rJFO+JTKSA6/Rwi0getWmtuy4Itup0AMcaDQ==", + "dev": true, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/path-scurry": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", + "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", + "dev": true, + "dependencies": { + "lru-cache": "^10.2.0", + "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" + }, + "engines": { + "node": ">=16 || 14 >=14.18" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/read-cmd-shim": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/read-cmd-shim/-/read-cmd-shim-4.0.0.tgz", + "integrity": "sha512-yILWifhaSEEytfXI76kB9xEEiG1AiozaCJZ83A87ytjRiN+jVibXjedjCRNjoZviinhG+4UkalO3mWTd8u5O0Q==", + "dev": true, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/rimraf": { + "version": "5.0.7", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.7.tgz", + "integrity": "sha512-nV6YcJo5wbLW77m+8KjH8aB/7/rxQy9SZ0HY5shnwULfS+9nmTtVXAJET5NdZmCzA4fPI/Hm1wo/Po/4mopOdg==", + "dev": true, + "dependencies": { + "glob": "^10.3.7" + }, + "bin": { + "rimraf": "dist/esm/bin.mjs" + }, + "engines": { + "node": ">=14.18" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, + "dependencies": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/string-width-cjs": { + "name": "string-width", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/string-width-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/string-width-cjs/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "node_modules/string-width-cjs/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/strip-ansi-cjs": { + "name": "strip-ansi", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/supabase": { + "version": "1.167.4", + "resolved": "https://registry.npmjs.org/supabase/-/supabase-1.167.4.tgz", + "integrity": "sha512-DTaTsYQ48FdOPvTTl3H1cQnGDHvm4kQdBakeI5qbs7BFZgu2SRJDYRrCcSgH9sbZReOKrQdJCPfNpoy/Z359gA==", + "dev": true, + "hasInstallScript": true, + "dependencies": { + "bin-links": "^4.0.3", + "https-proxy-agent": "^7.0.2", + "node-fetch": "^3.3.2", + "tar": "7.1.0" + }, + "bin": { + "supabase": "bin/supabase" + }, + "engines": { + "npm": ">=8" + } + }, + "node_modules/tar": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/tar/-/tar-7.1.0.tgz", + "integrity": "sha512-ENhg4W6BmjYxl8GTaE7/h99f0aXiSWv4kikRZ9n2/JRxypZniE84ILZqimAhxxX7Zb8Px6pFdheW3EeHfhnXQQ==", + "dev": true, + "dependencies": { + "@isaacs/fs-minipass": "^4.0.0", + "chownr": "^3.0.0", + "minipass": "^7.1.0", + "minizlib": "^3.0.1", + "mkdirp": "^3.0.1", + "yallist": "^5.0.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/web-streams-polyfill": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", + "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/wrap-ansi": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs": { + "name": "wrap-ansi", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "node_modules/wrap-ansi-cjs/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/write-file-atomic": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-5.0.1.tgz", + "integrity": "sha512-+QU2zd6OTD8XWIJCbffaiQeH9U73qIqafo1x6V1snCWYGJf6cVE0cDR4D8xRzcEnfI21IFrUPzPGtcPf8AC+Rw==", + "dev": true, + "dependencies": { + "imurmurhash": "^0.1.4", + "signal-exit": "^4.0.1" + }, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/yallist": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-5.0.0.tgz", + "integrity": "sha512-YgvUTfwqyc7UXVMrB+SImsVYSmTS8X/tSrtdNZMImM+n7+QTriRXyXim0mBrTXNeqzVF0KWGgHPeiyViFFrNDw==", + "dev": true, + "engines": { + "node": ">=18" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..098a854 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "ccc-databased", + "private": true, + "version": "1.0.0", + "description": "approximate caution, approximate context", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "AGPL-3", + "devDependencies": { + "supabase": "^1.167.4" + } +} diff --git a/supabase/.gitignore b/supabase/.gitignore new file mode 100644 index 0000000..a3ad880 --- /dev/null +++ b/supabase/.gitignore @@ -0,0 +1,4 @@ +# Supabase +.branches +.temp +.env diff --git a/supabase/config.toml b/supabase/config.toml new file mode 100644 index 0000000..7cde4da --- /dev/null +++ b/supabase/config.toml @@ -0,0 +1,171 @@ +# A string used to distinguish different Supabase projects on the same host. Defaults to the +# working directory name when running `supabase init`. +project_id = "ccc-databased" + +[api] +enabled = true +# Port to use for the API URL. +port = 54321 +# Schemas to expose in your API. Tables, views and stored procedures in this schema will get API +# endpoints. `public` is always included. +schemas = ["public", "graphql_public"] +# Extra schemas to add to the search_path of every request. `public` is always included. +extra_search_path = ["public", "extensions"] +# The maximum number of rows returns from a view, table, or stored procedure. Limits payload size +# for accidental or malicious requests. +max_rows = 1000 + +[db] +# Port to use for the local database URL. +port = 54322 +# Port used by db diff command to initialize the shadow database. +shadow_port = 54320 +# The database major version to use. This has to be the same as your remote database's. Run `SHOW +# server_version;` on the remote database to check. +major_version = 15 + +[db.pooler] +enabled = false +# Port to use for the local connection pooler. +port = 54329 +# Specifies when a server connection can be reused by other clients. +# Configure one of the supported pooler modes: `transaction`, `session`. +pool_mode = "transaction" +# How many server connections to allow per user/database pair. +default_pool_size = 20 +# Maximum number of client connections allowed. +max_client_conn = 100 + +[realtime] +enabled = true +# Bind realtime via either IPv4 or IPv6. (default: IPv4) +# ip_version = "IPv6" +# The maximum length in bytes of HTTP request headers. (default: 4096) +# max_header_length = 4096 + +[studio] +enabled = true +# Port to use for Supabase Studio. +port = 54323 +# External URL of the API server that frontend connects to. +api_url = "http://127.0.0.1" +# OpenAI API Key to use for Supabase AI in the Supabase Studio. +openai_api_key = "env(OPENAI_API_KEY)" + +# Email testing server. Emails sent with the local dev setup are not actually sent - rather, they +# are monitored, and you can view the emails that would have been sent from the web interface. +[inbucket] +enabled = true +# Port to use for the email testing server web interface. +port = 54324 +# Uncomment to expose additional ports for testing user applications that send emails. +# smtp_port = 54325 +# pop3_port = 54326 + +[storage] +enabled = true +# The maximum file size allowed (e.g. "5MB", "500KB"). +file_size_limit = "50MiB" + +[storage.image_transformation] +enabled = true + +[auth] +enabled = true +# The base URL of your website. Used as an allow-list for redirects and for constructing URLs used +# in emails. +site_url = "http://127.0.0.1:3000" +# A list of *exact* URLs that auth providers are permitted to redirect to post authentication. +additional_redirect_urls = ["https://127.0.0.1:3000"] +# How long tokens are valid for, in seconds. Defaults to 3600 (1 hour), maximum 604,800 (1 week). +jwt_expiry = 3600 +# If disabled, the refresh token will never expire. +enable_refresh_token_rotation = true +# Allows refresh tokens to be reused after expiry, up to the specified interval in seconds. +# Requires enable_refresh_token_rotation = true. +refresh_token_reuse_interval = 10 +# Allow/disallow new user signups to your project. +enable_signup = true +# Allow/disallow anonymous sign-ins to your project. +enable_anonymous_sign_ins = false +# Allow/disallow testing manual linking of accounts +enable_manual_linking = false + +[auth.email] +# Allow/disallow new user signups via email to your project. +enable_signup = true +# If enabled, a user will be required to confirm any email change on both the old, and new email +# addresses. If disabled, only the new email is required to confirm. +double_confirm_changes = true +# If enabled, users need to confirm their email address before signing in. +enable_confirmations = false +# Controls the minimum amount of time that must pass before sending another signup confirmation or password reset email. +max_frequency = "1s" + +# Uncomment to customize email template +# [auth.email.template.invite] +# subject = "You have been invited" +# content_path = "./supabase/templates/invite.html" + +[auth.sms] +# Allow/disallow new user signups via SMS to your project. +enable_signup = true +# If enabled, users need to confirm their phone number before signing in. +enable_confirmations = false +# Template for sending OTP to users +template = "Your code is {{ .Code }} ." +# Controls the minimum amount of time that must pass before sending another sms otp. +max_frequency = "5s" + +# Use pre-defined map of phone number to OTP for testing. +# [auth.sms.test_otp] +# 4152127777 = "123456" + +# This hook runs before a token is issued and allows you to add additional claims based on the authentication method used. +# [auth.hook.custom_access_token] +# enabled = true +# uri = "pg-functions:////" + +# Configure one of the supported SMS providers: `twilio`, `twilio_verify`, `messagebird`, `textlocal`, `vonage`. +[auth.sms.twilio] +enabled = false +account_sid = "" +message_service_sid = "" +# DO NOT commit your Twilio auth token to git. Use environment variable substitution instead: +auth_token = "env(SUPABASE_AUTH_SMS_TWILIO_AUTH_TOKEN)" + +# Use an external OAuth provider. The full list of providers are: `apple`, `azure`, `bitbucket`, +# `discord`, `facebook`, `github`, `gitlab`, `google`, `keycloak`, `linkedin_oidc`, `notion`, `twitch`, +# `twitter`, `slack`, `spotify`, `workos`, `zoom`. +[auth.external.apple] +enabled = false +client_id = "" +# DO NOT commit your OAuth provider secret to git. Use environment variable substitution instead: +secret = "env(SUPABASE_AUTH_EXTERNAL_APPLE_SECRET)" +# Overrides the default auth redirectUrl. +redirect_uri = "" +# Overrides the default auth provider URL. Used to support self-hosted gitlab, single-tenant Azure, +# or any other third-party OIDC providers. +url = "" +# If enabled, the nonce check will be skipped. Required for local sign in with Google auth. +skip_nonce_check = false + +[analytics] +enabled = false +port = 54327 +vector_port = 54328 +# Configure one of the supported backends: `postgres`, `bigquery`. +backend = "postgres" + +# Experimental features may be deprecated any time +[experimental] +# Configures Postgres storage engine to use OrioleDB (S3) +orioledb_version = "" +# Configures S3 bucket URL, eg. .s3-.amazonaws.com +s3_host = "env(S3_HOST)" +# Configures S3 bucket region, eg. us-east-1 +s3_region = "env(S3_REGION)" +# Configures AWS_ACCESS_KEY_ID for S3 bucket +s3_access_key = "env(S3_ACCESS_KEY)" +# Configures AWS_SECRET_ACCESS_KEY for S3 bucket +s3_secret_key = "env(S3_SECRET_KEY)" diff --git a/supabase/seed.sql b/supabase/seed.sql new file mode 100644 index 0000000..e69de29 diff --git a/supabase/tests/database/hello_world.test.sql b/supabase/tests/database/hello_world.test.sql new file mode 100644 index 0000000..b25e006 --- /dev/null +++ b/supabase/tests/database/hello_world.test.sql @@ -0,0 +1,12 @@ +begin; +select plan(1); -- only one statement to run + +SELECT has_column( + 'auth', + 'users', + 'id', + 'id should exist' +); + +select * from finish(); +rollback; From 5d173ffc1cdc7e0619085ab1a7e6378d82b4ca7f Mon Sep 17 00:00:00 2001 From: Hawken Rives Date: Mon, 20 May 2024 19:17:55 -0400 Subject: [PATCH 02/14] add formatting check for migrations --- .github/workflows/database-tests.yml | 17 +++++ .node-version | 1 + package-lock.json | 101 +++++++++++++++++++++++++++ package.json | 1 + 4 files changed, 120 insertions(+) create mode 100644 .node-version diff --git a/.github/workflows/database-tests.yml b/.github/workflows/database-tests.yml index a4d26fc..87d6932 100644 --- a/.github/workflows/database-tests.yml +++ b/.github/workflows/database-tests.yml @@ -12,6 +12,23 @@ jobs: version: latest - run: supabase db lint + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v4 + with: + node-version-file: '.node-version' + - run: npm ci + - run: npx sql-formatter --fix --language postgresql ./supabase/migrations/*.sql + - name: Verify that no .sql files changed + run: | + if ! git diff --ignore-space-at-eol --exit-code --quiet; then + echo "Detected uncommitted changes after build. See status below:" + git diff + exit 1 + fi + test: runs-on: ubuntu-latest steps: diff --git a/.node-version b/.node-version new file mode 100644 index 0000000..2bd5a0a --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +22 diff --git a/package-lock.json b/package-lock.json index 26ea404..73f2d68 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "AGPL-3", "devDependencies": { + "sql-formatter": "^15.3.1", "supabase": "^1.167.4" } }, @@ -87,6 +88,12 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -153,6 +160,12 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -193,6 +206,12 @@ } } }, + "node_modules/discontinuous-range": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/discontinuous-range/-/discontinuous-range-1.0.0.tgz", + "integrity": "sha512-c68LpLbO+7kP/b1Hr1qs8/BJ09F5khZGTxqxZuhzxpmwJKOgRFHJWIb9/KmqnqHhLdO55aOxFH/EGBvUQbL/RQ==", + "dev": true + }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -256,6 +275,18 @@ "node": ">=12.20.0" } }, + "node_modules/get-stdin": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-8.0.0.tgz", + "integrity": "sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/glob": { "version": "10.3.15", "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.15.tgz", @@ -394,12 +425,40 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/moo": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/moo/-/moo-0.5.2.tgz", + "integrity": "sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q==", + "dev": true + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, + "node_modules/nearley": { + "version": "2.20.1", + "resolved": "https://registry.npmjs.org/nearley/-/nearley-2.20.1.tgz", + "integrity": "sha512-+Mc8UaAebFzgV+KpI5n7DasuuQCHA89dmwm7JXw3TV43ukfNQ9DnBH3Mdb2g/I4Fdxc26pwimBWvjIw0UAILSQ==", + "dev": true, + "dependencies": { + "commander": "^2.19.0", + "moo": "^0.5.0", + "railroad-diagrams": "^1.0.0", + "randexp": "0.4.6" + }, + "bin": { + "nearley-railroad": "bin/nearley-railroad.js", + "nearley-test": "bin/nearley-test.js", + "nearley-unparse": "bin/nearley-unparse.js", + "nearleyc": "bin/nearleyc.js" + }, + "funding": { + "type": "individual", + "url": "https://nearley.js.org/#give-to-nearley" + } + }, "node_modules/node-domexception": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", @@ -471,6 +530,25 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/railroad-diagrams": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz", + "integrity": "sha512-cz93DjNeLY0idrCNOH6PviZGRN9GJhsdm9hpn1YCS879fj4W+x5IFJhhkRZcwVgMmFF7R82UA/7Oh+R8lLZg6A==", + "dev": true + }, + "node_modules/randexp": { + "version": "0.4.6", + "resolved": "https://registry.npmjs.org/randexp/-/randexp-0.4.6.tgz", + "integrity": "sha512-80WNmd9DA0tmZrw9qQa62GPPWfuXJknrmVmLcxvq4uZBdYqb1wYoKTmnlGUchvVWe0XiLupYkBoXVOxz3C8DYQ==", + "dev": true, + "dependencies": { + "discontinuous-range": "1.0.0", + "ret": "~0.1.10" + }, + "engines": { + "node": ">=0.12" + } + }, "node_modules/read-cmd-shim": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/read-cmd-shim/-/read-cmd-shim-4.0.0.tgz", @@ -480,6 +558,15 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, + "node_modules/ret": { + "version": "0.1.15", + "resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz", + "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", + "dev": true, + "engines": { + "node": ">=0.12" + } + }, "node_modules/rimraf": { "version": "5.0.7", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.7.tgz", @@ -531,6 +618,20 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/sql-formatter": { + "version": "15.3.1", + "resolved": "https://registry.npmjs.org/sql-formatter/-/sql-formatter-15.3.1.tgz", + "integrity": "sha512-L/dqan+Hrt0PpPdCbHcI9bdfOvqaQZR7v5c5SWMJ3bUGQSezK09Mm9q2I3B4iObjaq7FyoldIM+fDSmfzGRXCA==", + "dev": true, + "dependencies": { + "argparse": "^2.0.1", + "get-stdin": "=8.0.0", + "nearley": "^2.20.1" + }, + "bin": { + "sql-formatter": "bin/sql-formatter-cli.cjs" + } + }, "node_modules/string-width": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", diff --git a/package.json b/package.json index 098a854..04326a9 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "author": "", "license": "AGPL-3", "devDependencies": { + "sql-formatter": "^15.3.1", "supabase": "^1.167.4" } } From 257ba1aaff377786aa62ec11160ad1d4048ac1cc Mon Sep 17 00:00:00 2001 From: Hawken Rives Date: Mon, 20 May 2024 19:17:55 -0400 Subject: [PATCH 03/14] fix supabase project id --- supabase/config.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supabase/config.toml b/supabase/config.toml index 7cde4da..b3f3433 100644 --- a/supabase/config.toml +++ b/supabase/config.toml @@ -1,6 +1,6 @@ # A string used to distinguish different Supabase projects on the same host. Defaults to the # working directory name when running `supabase init`. -project_id = "ccc-databased" +project_id = "kusrnwijckyfvnkqdurl" [api] enabled = true From 6a91d17a4ec6ffea96d9367a809a0425014dd812 Mon Sep 17 00:00:00 2001 From: Hawken Rives Date: Mon, 20 May 2024 19:17:55 -0400 Subject: [PATCH 04/14] add seed data and initial migrations --- .../20240520215620_create_data_source.sql | 22 +++ .../migrations/20240520215621_create_link.sql | 24 +++ .../20240520215622_create_dictionary.sql | 21 +++ .../20240520215623_create_metadata.sql | 14 ++ ...0240520215624_create_location_category.sql | 14 ++ .../20240520215625_create_location.sql | 26 +++ ...0240520215626_create_location_schedule.sql | 24 +++ ...627_create_location_schedule_timetable.sql | 16 ++ .../20240520215628_create_directory_entry.sql | 25 +++ ...215629_create_directory_entry_category.sql | 13 ++ ...215630_create_directory_entry_location.sql | 19 ++ ...31_create_directory_entry_organization.sql | 20 +++ ...20240520215632_create_content_category.sql | 13 ++ .../20240520215633_create_calendar_event.sql | 23 +++ ...0215634_create_calendar_event_category.sql | 14 ++ ...40520215635_create_calendar_event_link.sql | 17 ++ .../migrations/20240520215636_create_feed.sql | 14 ++ .../20240520215637_create_feed_article.sql | 22 +++ ...520215638_create_feed_article_category.sql | 13 ++ .../20240520215639_create_app_notice.sql | 21 +++ .../20240520215640_create_livestream.sql | 22 +++ .../20240520215641_create_bus_route.sql | 14 ++ .../20240520215642_create_bus_route_stop.sql | 14 ++ ...40520215643_create_bus_route_timetable.sql | 18 ++ ...240520215644_create_bus_route_schedule.sql | 15 ++ .../migrations/20240520215645_create_cafe.sql | 15 ++ .../20240520215646_create_cafe_cor.sql | 15 ++ .../20240520215647_create_cafe_item.sql | 18 ++ ...40520215648_create_cafe_item_variation.sql | 14 ++ .../20240520215649_create_cafe_item_cor.sql | 14 ++ ...0240520215650_create_cafe_station_menu.sql | 19 ++ ...240520215651_create_cafe_menu_schedule.sql | 14 ++ .../20240520215652_create_student_work.sql | 28 +++ supabase/seed.sql | 165 ++++++++++++++++++ 34 files changed, 760 insertions(+) create mode 100644 supabase/migrations/20240520215620_create_data_source.sql create mode 100644 supabase/migrations/20240520215621_create_link.sql create mode 100644 supabase/migrations/20240520215622_create_dictionary.sql create mode 100644 supabase/migrations/20240520215623_create_metadata.sql create mode 100644 supabase/migrations/20240520215624_create_location_category.sql create mode 100644 supabase/migrations/20240520215625_create_location.sql create mode 100644 supabase/migrations/20240520215626_create_location_schedule.sql create mode 100644 supabase/migrations/20240520215627_create_location_schedule_timetable.sql create mode 100644 supabase/migrations/20240520215628_create_directory_entry.sql create mode 100644 supabase/migrations/20240520215629_create_directory_entry_category.sql create mode 100644 supabase/migrations/20240520215630_create_directory_entry_location.sql create mode 100644 supabase/migrations/20240520215631_create_directory_entry_organization.sql create mode 100644 supabase/migrations/20240520215632_create_content_category.sql create mode 100644 supabase/migrations/20240520215633_create_calendar_event.sql create mode 100644 supabase/migrations/20240520215634_create_calendar_event_category.sql create mode 100644 supabase/migrations/20240520215635_create_calendar_event_link.sql create mode 100644 supabase/migrations/20240520215636_create_feed.sql create mode 100644 supabase/migrations/20240520215637_create_feed_article.sql create mode 100644 supabase/migrations/20240520215638_create_feed_article_category.sql create mode 100644 supabase/migrations/20240520215639_create_app_notice.sql create mode 100644 supabase/migrations/20240520215640_create_livestream.sql create mode 100644 supabase/migrations/20240520215641_create_bus_route.sql create mode 100644 supabase/migrations/20240520215642_create_bus_route_stop.sql create mode 100644 supabase/migrations/20240520215643_create_bus_route_timetable.sql create mode 100644 supabase/migrations/20240520215644_create_bus_route_schedule.sql create mode 100644 supabase/migrations/20240520215645_create_cafe.sql create mode 100644 supabase/migrations/20240520215646_create_cafe_cor.sql create mode 100644 supabase/migrations/20240520215647_create_cafe_item.sql create mode 100644 supabase/migrations/20240520215648_create_cafe_item_variation.sql create mode 100644 supabase/migrations/20240520215649_create_cafe_item_cor.sql create mode 100644 supabase/migrations/20240520215650_create_cafe_station_menu.sql create mode 100644 supabase/migrations/20240520215651_create_cafe_menu_schedule.sql create mode 100644 supabase/migrations/20240520215652_create_student_work.sql diff --git a/supabase/migrations/20240520215620_create_data_source.sql b/supabase/migrations/20240520215620_create_data_source.sql new file mode 100644 index 0000000..a16fd7b --- /dev/null +++ b/supabase/migrations/20240520215620_create_data_source.sql @@ -0,0 +1,22 @@ +create table data_source ( + id text not null primary key, + type text not null check (type in ('manual', 'automated-scrape', 'scrape')), + uri text check ( + case + when type != 'manual' then uri is not null + end + ) +); + +comment on table data_source is 'the authoritative list of data sources, including manual data entry'; + +comment on column data_source.type is 'what type of source is this?'; + +comment on column data_source.uri is 'where did we start this scrape from?'; + +alter table data_source enable row level security; + +create policy "data_source are viewable by everyone" on data_source for +select + to authenticated, + anon using (true); diff --git a/supabase/migrations/20240520215621_create_link.sql b/supabase/migrations/20240520215621_create_link.sql new file mode 100644 index 0000000..a0eb6c9 --- /dev/null +++ b/supabase/migrations/20240520215621_create_link.sql @@ -0,0 +1,24 @@ +create table link +( + source text not null references data_source (id) on update cascade on delete cascade, + type text not null check (type in + ('a-z', 'webcam', 'help', 'transit', 'contact', 'definition', + 'app-link', 'app-faq', 'app-tool')), + uri text not null default '', + title text not null check (length(title) < 1024), + sort_title text null check (length(sort_title) < 1024), + subtitle text not null default '' check (length(subtitle) < 1024), + description text not null default '' check (length(description) < 65536), + tint_color text not null default '#fff', + text_color text not null default '#000', + image_uri text, + sort_group text not null default '', + primary key (type, title) +); + +alter table link enable row level security; + +create policy "link are viewable by everyone" +on link for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215622_create_dictionary.sql b/supabase/migrations/20240520215622_create_dictionary.sql new file mode 100644 index 0000000..d5b4e66 --- /dev/null +++ b/supabase/migrations/20240520215622_create_dictionary.sql @@ -0,0 +1,21 @@ +create table dictionary +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + uri text not null default '', + title text not null check (length(title) < 1024), + sort_title text null check (length(sort_title) < 1024), + subtitle text not null default '' check (length(subtitle) < 1024), + description text not null default '' check (length(description) < 65536), + tint_color text not null default '#fff', + text_color text not null default '#000', + image_uri text, + sort_group text not null generated always as ( left(upper(sort_title), 1) ) stored +); + +alter table dictionary enable row level security; + +create policy "dictionary is viewable by everyone" +on dictionary for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215623_create_metadata.sql b/supabase/migrations/20240520215623_create_metadata.sql new file mode 100644 index 0000000..87a328a --- /dev/null +++ b/supabase/migrations/20240520215623_create_metadata.sql @@ -0,0 +1,14 @@ +create table metadata +( + source text not null references data_source (id) on update cascade on delete cascade, + key text not null check (key in ('app-version', 'color-printer')), + value text not null default '' check (length(value) < 1024), + primary key (key, value) +); + +alter table metadata enable row level security; + +create policy "metadata is viewable by everyone" +on metadata for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215624_create_location_category.sql b/supabase/migrations/20240520215624_create_location_category.sql new file mode 100644 index 0000000..09d80be --- /dev/null +++ b/supabase/migrations/20240520215624_create_location_category.sql @@ -0,0 +1,14 @@ +create table location_category +( + id uuid not null default uuid_generate_v4() primary key, + title text not null unique check (length(title) between 0 and 256), + sort_title text unique check (length(sort_title) between 0 and 256), + source text not null references data_source (id) on update cascade on delete cascade +); + +alter table location_category enable row level security; + +create policy "location_category is viewable by everyone" +on location_category for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215625_create_location.sql b/supabase/migrations/20240520215625_create_location.sql new file mode 100644 index 0000000..f8c07b2 --- /dev/null +++ b/supabase/migrations/20240520215625_create_location.sql @@ -0,0 +1,26 @@ +create table location +( + id uuid not null default uuid_generate_v4() primary key, + source text not null default 'manual', + within uuid references location (id) on update cascade on delete restrict, + category uuid not null references location_category (id) on update cascade on delete restrict, -- TODO: keep as 1-1, or allow multiple? + title text not null default '', + subtitle text not null default '', + abbreviation text not null default '', + room_number text not null default '', + outline_shape jsonb not null default '[]'::jsonb, -- geojson + coordinates jsonb not null default '[]'::jsonb, + -- todo: keep these? + banner_uri text not null default '', + icon_uri text not null default '', + website_uri text not null default '', + phone text not null default '', + email text not null default '' +); + +alter table location enable row level security; + +create policy "location is viewable by everyone" +on location for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215626_create_location_schedule.sql b/supabase/migrations/20240520215626_create_location_schedule.sql new file mode 100644 index 0000000..d45725c --- /dev/null +++ b/supabase/migrations/20240520215626_create_location_schedule.sql @@ -0,0 +1,24 @@ +create table location_schedule +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + parent_schedule uuid null references location_schedule (id) on update cascade on delete cascade, + location_category uuid null references location_category (id), + location uuid null references location (id), + title text not null, + status text not null default 'open' check (status in ('open', 'closed')), + message text null check (case when status != 'open' then message is not null end), + active_from timestamptz not null, + active_until timestamptz null, + audience text not null default '*' check (audience in ('*', 'students', 'seniors', 'facstaff')), + constraint category_or_location check (case + when location_category is not null then location is null + when location is null then location_category is not null end) +); + +alter table location_schedule enable row level security; + +create policy "location_schedule is viewable by everyone" +on location_schedule for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215627_create_location_schedule_timetable.sql b/supabase/migrations/20240520215627_create_location_schedule_timetable.sql new file mode 100644 index 0000000..f4cc3df --- /dev/null +++ b/supabase/migrations/20240520215627_create_location_schedule_timetable.sql @@ -0,0 +1,16 @@ +create table location_schedule_timetable +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id), + location_schedule_id uuid not null references location_schedule (id), + days text not null, + open_at time not null, + open_for interval minute not null +); + +alter table location_schedule_timetable enable row level security; + +create policy "location_schedule_timetable is viewable by everyone" +on location_schedule_timetable for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215628_create_directory_entry.sql b/supabase/migrations/20240520215628_create_directory_entry.sql new file mode 100644 index 0000000..4946e42 --- /dev/null +++ b/supabase/migrations/20240520215628_create_directory_entry.sql @@ -0,0 +1,25 @@ +create table directory_entry +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + name text not null, + sort_name text not null, + -- todo: do we need this field? + type text not null check (type in ('individual', 'department', 'organization')), + phone text, + email text, + pronouns text, + profile_uri text, + profile_text text, + title text, + photo text, + office_hours text, + specialties text +); + +alter table directory_entry enable row level security; + +create policy "directory_entry is viewable by everyone" +on directory_entry for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215629_create_directory_entry_category.sql b/supabase/migrations/20240520215629_create_directory_entry_category.sql new file mode 100644 index 0000000..dcd88c9 --- /dev/null +++ b/supabase/migrations/20240520215629_create_directory_entry_category.sql @@ -0,0 +1,13 @@ +-- TODO: what is this for, again? +create table directory_entry_category +( + directory_entry uuid references directory_entry (id) on update cascade on delete cascade, + category text not null check (length(trim(category)) > 0) +); + +alter table directory_entry_category enable row level security; + +create policy "directory_entry_category is viewable by everyone" +on directory_entry_category for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215630_create_directory_entry_location.sql b/supabase/migrations/20240520215630_create_directory_entry_location.sql new file mode 100644 index 0000000..adb58fb --- /dev/null +++ b/supabase/migrations/20240520215630_create_directory_entry_location.sql @@ -0,0 +1,19 @@ +create table directory_entry_location +( + directory_entry uuid not null references directory_entry (id) on update cascade on delete cascade, + location uuid not null references location (id) on update cascade on delete cascade, + source text not null references data_source (id) on update cascade on delete cascade, + title text, + email text, + phone text, + fax text, + hours text, -- can we use a schedule record for this? probably not... + description text +); + +alter table directory_entry_location enable row level security; + +create policy "directory_entry_location is viewable by everyone" +on directory_entry_location for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215631_create_directory_entry_organization.sql b/supabase/migrations/20240520215631_create_directory_entry_organization.sql new file mode 100644 index 0000000..15f4bc8 --- /dev/null +++ b/supabase/migrations/20240520215631_create_directory_entry_organization.sql @@ -0,0 +1,20 @@ +create table directory_entry_organization +( + directory_entry uuid not null references directory_entry (id) on update cascade on delete cascade, + directory_organization uuid not null references directory_entry (id) on update cascade on delete cascade, + source text not null references data_source (id) on update cascade on delete cascade, + role text, -- not sure if needed, or if can be replaced with title + title text, + email text, + phone text, + fax text, + hours text, -- can we use a schedule record for this? probably not... + description text +); + +alter table directory_entry_organization enable row level security; + +create policy "directory_entry_organization is viewable by everyone" +on directory_entry_organization for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215632_create_content_category.sql b/supabase/migrations/20240520215632_create_content_category.sql new file mode 100644 index 0000000..69b6df7 --- /dev/null +++ b/supabase/migrations/20240520215632_create_content_category.sql @@ -0,0 +1,13 @@ +create table content_category +( + id uuid not null default uuid_generate_v4() primary key, + title text not null unique check (length(title) between 0 and 256), + sort_title text null unique check (length(sort_title) between 0 and 256) +); + +alter table content_category enable row level security; + +create policy "content_category is viewable by everyone" +on content_category for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215633_create_calendar_event.sql b/supabase/migrations/20240520215633_create_calendar_event.sql new file mode 100644 index 0000000..acd2e94 --- /dev/null +++ b/supabase/migrations/20240520215633_create_calendar_event.sql @@ -0,0 +1,23 @@ +create table calendar_event +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + recurrence_of_event_id uuid null references calendar_event (id) on update cascade on delete cascade, + start_time timestamptz not null, + end_time timestamptz not null check (end_time >= start_time), + title text not null check (length(title) > 0), + description text not null default '', + thumbnail_uri text null, + banner_uri text null, + sponsoring_entity uuid null references directory_entry (id) on update cascade on delete set null, + campus_location_id uuid null references location (id) on update cascade on delete set null, + textual_location text null, + constraint only_one_location check ( case when campus_location_id is not null then textual_location is null end ) +); + +alter table calendar_event enable row level security; + +create policy "calendar_event is viewable by everyone" +on calendar_event for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215634_create_calendar_event_category.sql b/supabase/migrations/20240520215634_create_calendar_event_category.sql new file mode 100644 index 0000000..1004d35 --- /dev/null +++ b/supabase/migrations/20240520215634_create_calendar_event_category.sql @@ -0,0 +1,14 @@ +create table calendar_event_category +( + calendar_event_id uuid not null references calendar_event (id) on update cascade on delete cascade, + category_id uuid not null references content_category (id) on update cascade on delete cascade, + source text not null references data_source (id) on update cascade on delete cascade, + primary key (calendar_event_id, category_id) +); + +alter table calendar_event_category enable row level security; + +create policy "calendar_event_category is viewable by everyone" +on calendar_event_category for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215635_create_calendar_event_link.sql b/supabase/migrations/20240520215635_create_calendar_event_link.sql new file mode 100644 index 0000000..8323b49 --- /dev/null +++ b/supabase/migrations/20240520215635_create_calendar_event_link.sql @@ -0,0 +1,17 @@ +create table calendar_event_link +( + calendar_event_id uuid not null references calendar_event (id) on update cascade on delete cascade, + source text not null references data_source (id) on update cascade on delete cascade, + href text not null, + title text not null, + content_type text, + link_mode text not null check (link_mode in ('a', 'stream')), + primary key (calendar_event_id, href) +); + +alter table calendar_event_link enable row level security; + +create policy "calendar_event_link is viewable by everyone" +on calendar_event_link for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215636_create_feed.sql b/supabase/migrations/20240520215636_create_feed.sql new file mode 100644 index 0000000..b90e69b --- /dev/null +++ b/supabase/migrations/20240520215636_create_feed.sql @@ -0,0 +1,14 @@ +create table feed +( + source text not null references data_source (id) on update cascade on delete cascade, + title text not null check (length(title) > 0), + uri text not null, + primary key (uri) +); + +alter table feed enable row level security; + +create policy "feed is viewable by everyone" +on feed for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215637_create_feed_article.sql b/supabase/migrations/20240520215637_create_feed_article.sql new file mode 100644 index 0000000..f6a1e2e --- /dev/null +++ b/supabase/migrations/20240520215637_create_feed_article.sql @@ -0,0 +1,22 @@ +create table feed_article +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + published_at timestamptz not null, + updated_at timestamptz null, + title text not null check (length(title) > 0), + body text not null default '', + thumbnail_uri text null, + banner_uri text null, + sponsoring_entity uuid null references directory_entry (id) on update cascade on delete set null, + campus_location_id uuid null references location (id) on update cascade on delete set null, + textual_location text null, + constraint only_one_location check ( case when campus_location_id is not null then textual_location is null end ) +); + +alter table feed_article enable row level security; + +create policy "feed_article is viewable by everyone" +on feed_article for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215638_create_feed_article_category.sql b/supabase/migrations/20240520215638_create_feed_article_category.sql new file mode 100644 index 0000000..7d527af --- /dev/null +++ b/supabase/migrations/20240520215638_create_feed_article_category.sql @@ -0,0 +1,13 @@ +create table feed_article_category +( + feed_article_id uuid not null references feed_article (id) on update cascade on delete cascade, + category_id uuid not null references content_category (id) on update cascade on delete cascade, + primary key (feed_article_id, category_id) +); + +alter table feed_article_category enable row level security; + +create policy "feed_article_category is viewable by everyone" +on feed_article_category for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215639_create_app_notice.sql b/supabase/migrations/20240520215639_create_app_notice.sql new file mode 100644 index 0000000..e435774 --- /dev/null +++ b/supabase/migrations/20240520215639_create_app_notice.sql @@ -0,0 +1,21 @@ +create table app_notice +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + created_at timestamptz not null default current_timestamp, + title text not null, + subtitle text null, + body text null, + severity text not null check (severity in ('stop', 'note', 'caution', 'plain')), -- taken from https://developer.apple.com/documentation/corefoundation/1534483-alert_levels + active_from timestamptz null, + active_until timestamptz null, + app_version text null, + platform text null +); + +alter table app_notice enable row level security; + +create policy "app_notice is viewable by everyone" +on app_notice for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215640_create_livestream.sql b/supabase/migrations/20240520215640_create_livestream.sql new file mode 100644 index 0000000..d0622d6 --- /dev/null +++ b/supabase/migrations/20240520215640_create_livestream.sql @@ -0,0 +1,22 @@ +create table livestream +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + title text not null, + subtitle text not null, + stream_uri text not null, + tint_color text null, + text_color text null, + logo_uri text null, + calendar_source text null references data_source (id) on update cascade on delete restrict, + phone text null, + email text null, + website text null +); + +alter table livestream enable row level security; + +create policy "livestream is viewable by everyone" +on livestream for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215641_create_bus_route.sql b/supabase/migrations/20240520215641_create_bus_route.sql new file mode 100644 index 0000000..3828bf8 --- /dev/null +++ b/supabase/migrations/20240520215641_create_bus_route.sql @@ -0,0 +1,14 @@ +create table bus_route +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + key text not null, + title text not null +); + +alter table bus_route enable row level security; + +create policy "bus_route is viewable by everyone" +on bus_route for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215642_create_bus_route_stop.sql b/supabase/migrations/20240520215642_create_bus_route_stop.sql new file mode 100644 index 0000000..a31d49d --- /dev/null +++ b/supabase/migrations/20240520215642_create_bus_route_stop.sql @@ -0,0 +1,14 @@ +create table bus_route_stop +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + name text not null, + coordinates jsonb not null default '[]'::jsonb +); + +alter table bus_route_stop enable row level security; + +create policy "bus_route_stop is viewable by everyone" +on bus_route_stop for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215643_create_bus_route_timetable.sql b/supabase/migrations/20240520215643_create_bus_route_timetable.sql new file mode 100644 index 0000000..885b318 --- /dev/null +++ b/supabase/migrations/20240520215643_create_bus_route_timetable.sql @@ -0,0 +1,18 @@ +create table bus_route_timetable +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + inbound_stop uuid null references bus_route_stop (id), + inbound_time time null, + outbound_stop uuid null references bus_route_stop (id), + outbound_time time null, + constraint inbound_time_if_stop check (case when inbound_stop is not null then inbound_time is not null end), + constraint outbound_time_if_stop check (case when outbound_stop is not null then outbound_time is not null end) +); + +alter table bus_route_timetable enable row level security; + +create policy "bus_route_timetable is viewable by everyone" +on bus_route_timetable for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215644_create_bus_route_schedule.sql b/supabase/migrations/20240520215644_create_bus_route_schedule.sql new file mode 100644 index 0000000..b8d468c --- /dev/null +++ b/supabase/migrations/20240520215644_create_bus_route_schedule.sql @@ -0,0 +1,15 @@ +create table bus_route_schedule +( + bus_route_id uuid not null references bus_route (id) on update cascade on delete restrict, + timetable_id uuid not null references bus_route_timetable (id) on update cascade on delete restrict, + source text not null references data_source (id) on update cascade on delete cascade, + active_from timestamptz null, + active_until timestamptz null +); + +alter table bus_route_schedule enable row level security; + +create policy "bus_route_schedule is viewable by everyone" +on bus_route_schedule for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215645_create_cafe.sql b/supabase/migrations/20240520215645_create_cafe.sql new file mode 100644 index 0000000..e776d8f --- /dev/null +++ b/supabase/migrations/20240520215645_create_cafe.sql @@ -0,0 +1,15 @@ +create table cafe +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + name text not null, + description text, + location uuid null references location (id) +); + +alter table cafe enable row level security; + +create policy "cafe is viewable by everyone" +on cafe for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215646_create_cafe_cor.sql b/supabase/migrations/20240520215646_create_cafe_cor.sql new file mode 100644 index 0000000..f15fee5 --- /dev/null +++ b/supabase/migrations/20240520215646_create_cafe_cor.sql @@ -0,0 +1,15 @@ + +create table cafe_cor +( + id text not null primary key, + title text not null, + description text not null, + icon_uri text not null +); + +alter table cafe_cor enable row level security; + +create policy "cafe_cor is viewable by everyone" +on cafe_cor for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215647_create_cafe_item.sql b/supabase/migrations/20240520215647_create_cafe_item.sql new file mode 100644 index 0000000..6407f75 --- /dev/null +++ b/supabase/migrations/20240520215647_create_cafe_item.sql @@ -0,0 +1,18 @@ + +create table cafe_item +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + title text not null, + description text, + rating decimal, + monotony jsonb not null default '{}'::jsonb, -- TODO: expand this into a table + nutrition jsonb not null default '{}'::jsonb -- TODO: expand this into a table +); + +alter table cafe_item enable row level security; + +create policy "cafe_item is viewable by everyone" +on cafe_item for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215648_create_cafe_item_variation.sql b/supabase/migrations/20240520215648_create_cafe_item_variation.sql new file mode 100644 index 0000000..5a977ea --- /dev/null +++ b/supabase/migrations/20240520215648_create_cafe_item_variation.sql @@ -0,0 +1,14 @@ + +create table cafe_item_variation +( + cafe_item_id uuid not null references cafe_item (id), + title text not null, + description text +); + +alter table cafe_item_variation enable row level security; + +create policy "cafe_item_variation is viewable by everyone" +on cafe_item_variation for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215649_create_cafe_item_cor.sql b/supabase/migrations/20240520215649_create_cafe_item_cor.sql new file mode 100644 index 0000000..e698a89 --- /dev/null +++ b/supabase/migrations/20240520215649_create_cafe_item_cor.sql @@ -0,0 +1,14 @@ + +create table cafe_item_cor +( + cafe_item_id uuid not null references cafe_item (id), + cafe_cor_id text not null references cafe_cor (id), + primary key (cafe_item_id, cafe_cor_id) +); + +alter table cafe_item_cor enable row level security; + +create policy "cafe_item_cor is viewable by everyone" +on cafe_item_cor for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215650_create_cafe_station_menu.sql b/supabase/migrations/20240520215650_create_cafe_station_menu.sql new file mode 100644 index 0000000..e367d6a --- /dev/null +++ b/supabase/migrations/20240520215650_create_cafe_station_menu.sql @@ -0,0 +1,19 @@ + +create table cafe_station_menu +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + station_title text not null, + station_note text null, + station_sort_order integer not null, + item_id uuid not null references cafe_item (id) on update cascade on delete cascade, + item_sort_order integer not null, + is_featured bool not null default false +); + +alter table cafe_station_menu enable row level security; + +create policy "cafe_station_menu is viewable by everyone" +on cafe_station_menu for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215651_create_cafe_menu_schedule.sql b/supabase/migrations/20240520215651_create_cafe_menu_schedule.sql new file mode 100644 index 0000000..d506b43 --- /dev/null +++ b/supabase/migrations/20240520215651_create_cafe_menu_schedule.sql @@ -0,0 +1,14 @@ + +create table cafe_menu_schedule +( + schedule_id uuid not null references location_schedule (id), + station_id uuid not null references cafe_station_menu (id), + primary key (schedule_id, station_id) +); + +alter table cafe_menu_schedule enable row level security; + +create policy "cafe_menu_schedule is viewable by everyone" +on cafe_menu_schedule for select +to authenticated, anon +using ( true ); diff --git a/supabase/migrations/20240520215652_create_student_work.sql b/supabase/migrations/20240520215652_create_student_work.sql new file mode 100644 index 0000000..9b90c27 --- /dev/null +++ b/supabase/migrations/20240520215652_create_student_work.sql @@ -0,0 +1,28 @@ + +create table student_work +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + position_title text not null, + posted_at timestamptz not null, + category text not null check (category in ('Student Work', 'Summer Student Work')), + department_id uuid references directory_entry (id), + department_name text, + classification text, + position_duration text, + description text, + pay_rate text, + skills text, + duties text, + qualifications text, + constraint department_id_or_name check (case + when department_id is not null then department_name is null + when department_name is null then department_id is not null end) +); + +alter table student_work enable row level security; + +create policy "student_work is viewable by everyone" +on student_work for select +to authenticated, anon +using ( true ); diff --git a/supabase/seed.sql b/supabase/seed.sql index e69de29..4c26d94 100644 --- a/supabase/seed.sql +++ b/supabase/seed.sql @@ -0,0 +1,165 @@ +-- data source + +insert into data_source (type, id) +values ('manual', 'manual'); + +-- link + +INSERT INTO link (type, uri, title, subtitle, sort_group, source) +VALUES ('a-z', 'https://moodle.stolaf.edu', 'Moodle', '', 'M', 'manual'), + ('a-z', 'https://stolaf.edu/apps/tes', 'TES', 'Time Entry System', 'T', + 'manual'); + +INSERT INTO link (type, uri, title, sort_group, description, source) +VALUES ('transit', 'https://wp.stolaf.edu/transportation/', 'Transportation Options', 'All', + 'View all available transportation options on the St. Olaf website.', 'manual'); + +INSERT INTO link (type, uri, title, description, source, image_uri, tint_color, text_color) +VALUES ('webcam', 'https://www.stolaf.edu/multimedia/webcams/?cam=eastquad#fold', 'East Quad', + 'Looking out to Regents, Holland Hall, and Old Main', 'manual', + '/eastquad.png', '#525736', '#fff'); + +INSERT INTO link (type, uri, title, sort_group, description, source, image_uri) +VALUES ('contact', 'tel:+15077863666', 'St. Olaf Public Safety', 'Safety', + '**24-Hour Public Safety Dispatch.** [Public Safety][pubsafe] is available 24 hours a day, most days of the year. Call Public Safety in many situations, but there is always the option of calling the police as well. + +[pubsafe]: https://wp.stolaf.edu/publicsafety/ "PubSafe"', + 'manual', + '/pubsafe.png'); + +INSERT INTO link (type, uri, title, sort_group, description, source) +VALUES ('app-faq', '', '2am too often???', 'Known Issues', + 'Building Hours: It reports the 2am buildings as open too often; for instance, the Pause is open on Saturday at 2am, continuing from Friday, but the app reports it as being open on Friday at 2am, as well. This is incorrect.', + 'manual'); + +INSERT INTO link (type, uri, title, sort_group, description, source) +VALUES ('help', 'mailto:allaboutolaf@frogpond.tech?subject=A+Thing', 'Have an App Question?', '', + 'If you''ve got a question about the app, or a new feature idea, let us know!', + 'manual'); + +-- dictionary + +INSERT INTO dictionary (title, sort_title, description, source) +VALUES ('AAC', 'aac', 'The Academic Advising Center provides support in exploring academic goals within the context of possible career and life-long goals. The Center supports both faculty advisors and their advisees in providing the necessary information and skills to fulfill graduation, general education and major requirements. + +The Center also assists students in exploring possible major options, in changing faculty advisors, in using a degree audit, class/lab schedule, and the St. Olaf Catalog for necessary information about fulfilling requirements. + +Academic Peer Advisors assist the Center.', 'manual'); + +-- metadata + +insert into metadata (source, key, value) +values ('manual', 'app-version', '2.9.0'); + +insert into metadata (source, key, value) +values ('manual', 'color-printer', 'mfc-rml-4-disco'), + ('manual', 'color-printer', 'mfc-toh101'); + +-- location_category + +insert into location_category (title, source) +values ('Campus', 'manual'), + ('Faculty/Staff Office', 'manual'), + ('Café', 'manual'), + ('Building', 'manual'), + ('Department', 'manual'), + ('Supplies & Books', 'manual'), + ('Libraries', 'manual'), + ('Help & Support', 'manual'), + ('Gym & Exercise', 'manual'), + ('Health & Wellness', 'manual'), + ('Academia', 'manual'), + ('Residence Hall', 'manual'), + ('Museums & Studios', 'manual'); + +-- location + +insert into location (within, category, title, abbreviation, room_number) +values (null, (select id from location_category where title = 'Campus'), 'St. Olaf College', '', ''); + +insert into location (within, category, title, abbreviation) +values ((select id from location where title = 'St. Olaf College'), + (select id from location_category where title = 'Building'), + 'Regents Hall (Natural Science)', 'RNS') + , ((select id from location where title = 'St. Olaf College'), + (select id from location_category where title = 'Building'), + 'Buntrock Commons', 'BC') + , ((select id from location where title = 'St. Olaf College'), + (select id from location_category where title = 'Building'), + 'Regents Hall (Mathematical Science)', 'RMS') + , ((select id from location where title = 'St. Olaf College'), + (select id from location_category where title = 'Building'), + 'Rølvaag Memorial Library', 'RML') +; + +insert into location (within, category, title, room_number) +values ((select id from location where title = 'Regents Hall (Natural Science)'), + (select id from location_category where title = 'Department'), + 'Biology Office', '260') + , ((select id from location where title = 'Regents Hall (Natural Science)'), + (select id from location_category where title = 'Faculty/Staff Office'), + '', '412') + , ((select id from location where title = 'Buntrock Commons'), + (select id from location_category where title = 'Café'), + 'Stav Hall', '???') +; + +-- location_schedule + +insert into location_schedule (source, parent_schedule, location_category, location, title, active_from, active_until) +values ('manual', null, null, (select id from location where title = 'Stav Hall'), + 'Breakfast', '2024-01-01T00:00:00', null); + +-- location_schedule_timetable + +insert into location_schedule_timetable (source, location_schedule_id, days, open_at, open_for) +values ('manual', (select id from location_schedule where title = 'Breakfast'), + ':mo:tu:we:th:fr:', '07:15'::time, '2 hours 30 minutes'::interval), + ('manual', (select id from location_schedule where title = 'Breakfast'), + ':sa:', '08:00'::time, '1 hour 30 minutes'::interval), + ('manual', (select id from location_schedule where title = 'Breakfast'), + ':su:', '08:00'::time, '1 hour'::interval); + +-- directory_entry + +insert into directory_entry (name, source, sort_name, type, phone, email, pronouns, profile_uri, profile_text, title, + photo, office_hours, specialties) +values ('Barbara Barth', 'manual', 'Barth Barbara', 'individual', null, + 'barth@stolaf.edu', null, null, null, 'Academic Administrative Assistant - Team West', + 'https://www.stolaf.edu/stofaces/face.cfm?username=barth&v=298BFEA&fullsize', null, null); + +-- directory_entry_location + +insert into directory_entry_location (directory_entry, location, email, phone, fax, hours, description, source) +values ((select id from directory_entry where name = 'Barbara Barth'), + (select id from location limit 1 /* todo: fix */), + null, '+1-507-786-3568', null, null, null, 'manual'); + +-- content_category + +insert into content_category (title) +values ('Scheduling'), + ('Academics'), + ('Athletics'), + ('Alumni'), + ('Campaign'), + ('Campus and Community'), + ('Chapel'), + ('Conferences/Camps'), + ('Featured'), + ('Giving'), + ('Meetings/Workshops'), + ('Multicultural'), + ('Music'), + ('Performing and Visual Arts'), + ('Piper Center'), + ('Recreation'), + ('SGA and Student Life'), + ('Speakers/Lectures'), + ('Special Events/Celebrations'), + ('Vocation and Career'); + +-- bus_route + +insert into bus_route (source, key, title) +values ('manual', 'hiawathaland-blue-route', 'Blue Route'); From e7f4bbff3d1a3b3bbef30268e7ecec7cec19c12f Mon Sep 17 00:00:00 2001 From: Hawken Rives Date: Mon, 20 May 2024 19:17:55 -0400 Subject: [PATCH 05/14] remove formatting check for migrations --- .github/workflows/database-tests.yml | 17 ----- package-lock.json | 101 --------------------------- package.json | 1 - 3 files changed, 119 deletions(-) diff --git a/.github/workflows/database-tests.yml b/.github/workflows/database-tests.yml index 87d6932..a4d26fc 100644 --- a/.github/workflows/database-tests.yml +++ b/.github/workflows/database-tests.yml @@ -12,23 +12,6 @@ jobs: version: latest - run: supabase db lint - format: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v4 - with: - node-version-file: '.node-version' - - run: npm ci - - run: npx sql-formatter --fix --language postgresql ./supabase/migrations/*.sql - - name: Verify that no .sql files changed - run: | - if ! git diff --ignore-space-at-eol --exit-code --quiet; then - echo "Detected uncommitted changes after build. See status below:" - git diff - exit 1 - fi - test: runs-on: ubuntu-latest steps: diff --git a/package-lock.json b/package-lock.json index 73f2d68..26ea404 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "1.0.0", "license": "AGPL-3", "devDependencies": { - "sql-formatter": "^15.3.1", "supabase": "^1.167.4" } }, @@ -88,12 +87,6 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true - }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -160,12 +153,6 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, - "node_modules/commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", - "dev": true - }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -206,12 +193,6 @@ } } }, - "node_modules/discontinuous-range": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/discontinuous-range/-/discontinuous-range-1.0.0.tgz", - "integrity": "sha512-c68LpLbO+7kP/b1Hr1qs8/BJ09F5khZGTxqxZuhzxpmwJKOgRFHJWIb9/KmqnqHhLdO55aOxFH/EGBvUQbL/RQ==", - "dev": true - }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -275,18 +256,6 @@ "node": ">=12.20.0" } }, - "node_modules/get-stdin": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-8.0.0.tgz", - "integrity": "sha512-sY22aA6xchAzprjyqmSEQv4UbAAzRN0L2dQB0NlN5acTTK9Don6nhoc3eAbUnpZiCANAMfd/+40kVdKfFygohg==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/glob": { "version": "10.3.15", "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.15.tgz", @@ -425,40 +394,12 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/moo": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/moo/-/moo-0.5.2.tgz", - "integrity": "sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q==", - "dev": true - }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, - "node_modules/nearley": { - "version": "2.20.1", - "resolved": "https://registry.npmjs.org/nearley/-/nearley-2.20.1.tgz", - "integrity": "sha512-+Mc8UaAebFzgV+KpI5n7DasuuQCHA89dmwm7JXw3TV43ukfNQ9DnBH3Mdb2g/I4Fdxc26pwimBWvjIw0UAILSQ==", - "dev": true, - "dependencies": { - "commander": "^2.19.0", - "moo": "^0.5.0", - "railroad-diagrams": "^1.0.0", - "randexp": "0.4.6" - }, - "bin": { - "nearley-railroad": "bin/nearley-railroad.js", - "nearley-test": "bin/nearley-test.js", - "nearley-unparse": "bin/nearley-unparse.js", - "nearleyc": "bin/nearleyc.js" - }, - "funding": { - "type": "individual", - "url": "https://nearley.js.org/#give-to-nearley" - } - }, "node_modules/node-domexception": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", @@ -530,25 +471,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/railroad-diagrams": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz", - "integrity": "sha512-cz93DjNeLY0idrCNOH6PviZGRN9GJhsdm9hpn1YCS879fj4W+x5IFJhhkRZcwVgMmFF7R82UA/7Oh+R8lLZg6A==", - "dev": true - }, - "node_modules/randexp": { - "version": "0.4.6", - "resolved": "https://registry.npmjs.org/randexp/-/randexp-0.4.6.tgz", - "integrity": "sha512-80WNmd9DA0tmZrw9qQa62GPPWfuXJknrmVmLcxvq4uZBdYqb1wYoKTmnlGUchvVWe0XiLupYkBoXVOxz3C8DYQ==", - "dev": true, - "dependencies": { - "discontinuous-range": "1.0.0", - "ret": "~0.1.10" - }, - "engines": { - "node": ">=0.12" - } - }, "node_modules/read-cmd-shim": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/read-cmd-shim/-/read-cmd-shim-4.0.0.tgz", @@ -558,15 +480,6 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, - "node_modules/ret": { - "version": "0.1.15", - "resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz", - "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", - "dev": true, - "engines": { - "node": ">=0.12" - } - }, "node_modules/rimraf": { "version": "5.0.7", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-5.0.7.tgz", @@ -618,20 +531,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/sql-formatter": { - "version": "15.3.1", - "resolved": "https://registry.npmjs.org/sql-formatter/-/sql-formatter-15.3.1.tgz", - "integrity": "sha512-L/dqan+Hrt0PpPdCbHcI9bdfOvqaQZR7v5c5SWMJ3bUGQSezK09Mm9q2I3B4iObjaq7FyoldIM+fDSmfzGRXCA==", - "dev": true, - "dependencies": { - "argparse": "^2.0.1", - "get-stdin": "=8.0.0", - "nearley": "^2.20.1" - }, - "bin": { - "sql-formatter": "bin/sql-formatter-cli.cjs" - } - }, "node_modules/string-width": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", diff --git a/package.json b/package.json index 04326a9..098a854 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "author": "", "license": "AGPL-3", "devDependencies": { - "sql-formatter": "^15.3.1", "supabase": "^1.167.4" } } From 5a72f9de1756f3b3cbd664fe4caf645ac5b5ad33 Mon Sep 17 00:00:00 2001 From: Hawken Rives Date: Mon, 20 May 2024 19:17:55 -0400 Subject: [PATCH 06/14] fix an extra init --- .github/workflows/generate-types.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/generate-types.yml b/.github/workflows/generate-types.yml index b7a5699..3e4f5a5 100644 --- a/.github/workflows/generate-types.yml +++ b/.github/workflows/generate-types.yml @@ -10,7 +10,6 @@ jobs: - uses: supabase/setup-cli@v1 with: version: latest - - run: supabase init - run: supabase db start - name: Verify generated types match Postgres schema run: | From 00a4f741b1ec3120a0741c59ca11b07eebd91d16 Mon Sep 17 00:00:00 2001 From: Hawken Rives Date: Mon, 20 May 2024 19:17:55 -0400 Subject: [PATCH 07/14] start the db for linting --- .github/workflows/database-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/database-tests.yml b/.github/workflows/database-tests.yml index a4d26fc..8ebbb0b 100644 --- a/.github/workflows/database-tests.yml +++ b/.github/workflows/database-tests.yml @@ -10,6 +10,7 @@ jobs: - uses: supabase/setup-cli@v1 with: version: latest + - run: supabase db start - run: supabase db lint test: From a19b3c8af16a616b9358c16fa381857d6cb12949 Mon Sep 17 00:00:00 2001 From: Hawken Rives Date: Tue, 21 May 2024 12:52:11 -0400 Subject: [PATCH 08/14] reorganize the initial schema a bit --- .../20240520215620_create_data_source.sql | 24 ++-- .../migrations/20240520215621_create_link.sql | 16 +-- .../20240520215622_create_dictionary.sql | 9 +- .../20240520215623_create_metadata.sql | 9 +- ...0240520215624_create_location_category.sql | 14 --- .../20240520215625_create_location.sql | 39 ++++++- ...0240520215626_create_location_schedule.sql | 27 ++++- ...627_create_location_schedule_timetable.sql | 16 --- .../20240520215628_create_directory_entry.sql | 67 ++++++++++- ...215629_create_directory_entry_category.sql | 13 --- ...215630_create_directory_entry_location.sql | 19 --- ...31_create_directory_entry_organization.sql | 20 ---- ...20240520215632_create_content_category.sql | 9 +- .../20240520215633_create_calendar_event.sql | 44 ++++++- ...0215634_create_calendar_event_category.sql | 14 --- ...40520215635_create_calendar_event_link.sql | 17 --- .../migrations/20240520215636_create_feed.sql | 48 +++++++- .../20240520215637_create_feed_article.sql | 22 ---- ...520215638_create_feed_article_category.sql | 13 --- .../20240520215639_create_app_notice.sql | 9 +- .../20240520215640_create_livestream.sql | 9 +- .../20240520215641_create_bus_route.sql | 62 +++++++++- .../20240520215642_create_bus_route_stop.sql | 14 --- ...40520215643_create_bus_route_timetable.sql | 18 --- ...240520215644_create_bus_route_schedule.sql | 15 --- .../migrations/20240520215645_create_cafe.sql | 109 +++++++++++++++++- .../20240520215646_create_cafe_cor.sql | 15 --- .../20240520215647_create_cafe_item.sql | 18 --- ...40520215648_create_cafe_item_variation.sql | 14 --- .../20240520215649_create_cafe_item_cor.sql | 14 --- ...0240520215650_create_cafe_station_menu.sql | 19 --- ...240520215651_create_cafe_menu_schedule.sql | 14 --- .../20240520215652_create_student_work.sql | 10 +- 33 files changed, 417 insertions(+), 363 deletions(-) delete mode 100644 supabase/migrations/20240520215624_create_location_category.sql delete mode 100644 supabase/migrations/20240520215627_create_location_schedule_timetable.sql delete mode 100644 supabase/migrations/20240520215629_create_directory_entry_category.sql delete mode 100644 supabase/migrations/20240520215630_create_directory_entry_location.sql delete mode 100644 supabase/migrations/20240520215631_create_directory_entry_organization.sql delete mode 100644 supabase/migrations/20240520215634_create_calendar_event_category.sql delete mode 100644 supabase/migrations/20240520215635_create_calendar_event_link.sql delete mode 100644 supabase/migrations/20240520215637_create_feed_article.sql delete mode 100644 supabase/migrations/20240520215638_create_feed_article_category.sql delete mode 100644 supabase/migrations/20240520215642_create_bus_route_stop.sql delete mode 100644 supabase/migrations/20240520215643_create_bus_route_timetable.sql delete mode 100644 supabase/migrations/20240520215644_create_bus_route_schedule.sql delete mode 100644 supabase/migrations/20240520215646_create_cafe_cor.sql delete mode 100644 supabase/migrations/20240520215647_create_cafe_item.sql delete mode 100644 supabase/migrations/20240520215648_create_cafe_item_variation.sql delete mode 100644 supabase/migrations/20240520215649_create_cafe_item_cor.sql delete mode 100644 supabase/migrations/20240520215650_create_cafe_station_menu.sql delete mode 100644 supabase/migrations/20240520215651_create_cafe_menu_schedule.sql diff --git a/supabase/migrations/20240520215620_create_data_source.sql b/supabase/migrations/20240520215620_create_data_source.sql index a16fd7b..9e0b27c 100644 --- a/supabase/migrations/20240520215620_create_data_source.sql +++ b/supabase/migrations/20240520215620_create_data_source.sql @@ -1,11 +1,8 @@ -create table data_source ( - id text not null primary key, - type text not null check (type in ('manual', 'automated-scrape', 'scrape')), - uri text check ( - case - when type != 'manual' then uri is not null - end - ) +create table data_source +( + id text not null primary key, + type text not null check (type in ('manual', 'automated-scrape', 'scrape')), + uri text check (case when type != 'manual' then uri is not null end) ); comment on table data_source is 'the authoritative list of data sources, including manual data entry'; @@ -14,9 +11,10 @@ comment on column data_source.type is 'what type of source is this?'; comment on column data_source.uri is 'where did we start this scrape from?'; -alter table data_source enable row level security; +alter table data_source + enable row level security; -create policy "data_source are viewable by everyone" on data_source for -select - to authenticated, - anon using (true); +create policy "data_source is viewable by everyone" + on data_source for select + to authenticated, + anon using (true); diff --git a/supabase/migrations/20240520215621_create_link.sql b/supabase/migrations/20240520215621_create_link.sql index a0eb6c9..9cc69ed 100644 --- a/supabase/migrations/20240520215621_create_link.sql +++ b/supabase/migrations/20240520215621_create_link.sql @@ -1,9 +1,8 @@ create table link ( source text not null references data_source (id) on update cascade on delete cascade, - type text not null check (type in - ('a-z', 'webcam', 'help', 'transit', 'contact', 'definition', - 'app-link', 'app-faq', 'app-tool')), + type text not null check (type in ('a-z', 'webcam', 'help', 'transit', 'contact', 'definition', 'app-link', + 'app-faq', 'app-tool')), uri text not null default '', title text not null check (length(title) < 1024), sort_title text null check (length(sort_title) < 1024), @@ -16,9 +15,10 @@ create table link primary key (type, title) ); -alter table link enable row level security; +alter table link + enable row level security; -create policy "link are viewable by everyone" -on link for select -to authenticated, anon -using ( true ); +create policy "link is viewable by everyone" + on link for select + to authenticated, anon + using (true); diff --git a/supabase/migrations/20240520215622_create_dictionary.sql b/supabase/migrations/20240520215622_create_dictionary.sql index d5b4e66..2111589 100644 --- a/supabase/migrations/20240520215622_create_dictionary.sql +++ b/supabase/migrations/20240520215622_create_dictionary.sql @@ -13,9 +13,10 @@ create table dictionary sort_group text not null generated always as ( left(upper(sort_title), 1) ) stored ); -alter table dictionary enable row level security; +alter table dictionary + enable row level security; create policy "dictionary is viewable by everyone" -on dictionary for select -to authenticated, anon -using ( true ); + on dictionary for select + to authenticated, anon + using (true); diff --git a/supabase/migrations/20240520215623_create_metadata.sql b/supabase/migrations/20240520215623_create_metadata.sql index 87a328a..2f8a383 100644 --- a/supabase/migrations/20240520215623_create_metadata.sql +++ b/supabase/migrations/20240520215623_create_metadata.sql @@ -6,9 +6,10 @@ create table metadata primary key (key, value) ); -alter table metadata enable row level security; +alter table metadata + enable row level security; create policy "metadata is viewable by everyone" -on metadata for select -to authenticated, anon -using ( true ); + on metadata for select + to authenticated, anon + using (true); diff --git a/supabase/migrations/20240520215624_create_location_category.sql b/supabase/migrations/20240520215624_create_location_category.sql deleted file mode 100644 index 09d80be..0000000 --- a/supabase/migrations/20240520215624_create_location_category.sql +++ /dev/null @@ -1,14 +0,0 @@ -create table location_category -( - id uuid not null default uuid_generate_v4() primary key, - title text not null unique check (length(title) between 0 and 256), - sort_title text unique check (length(sort_title) between 0 and 256), - source text not null references data_source (id) on update cascade on delete cascade -); - -alter table location_category enable row level security; - -create policy "location_category is viewable by everyone" -on location_category for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215625_create_location.sql b/supabase/migrations/20240520215625_create_location.sql index f8c07b2..0a114d9 100644 --- a/supabase/migrations/20240520215625_create_location.sql +++ b/supabase/migrations/20240520215625_create_location.sql @@ -1,3 +1,19 @@ +create table location_category +( + id uuid not null default uuid_generate_v4() primary key, + title text not null unique check (length(title) between 0 and 256), + sort_title text unique check (length(sort_title) between 0 and 256), + source text not null references data_source (id) on update cascade on delete cascade +); + +alter table location_category + enable row level security; + +create policy "location_category is viewable by everyone" + on location_category for select + to authenticated, anon + using (true); + create table location ( id uuid not null default uuid_generate_v4() primary key, @@ -18,9 +34,24 @@ create table location email text not null default '' ); -alter table location enable row level security; +alter table location + enable row level security; create policy "location is viewable by everyone" -on location for select -to authenticated, anon -using ( true ); + on location for select + to authenticated, anon + using (true); + +create table location_category_mapping +( + location_id uuid not null references location (id), + location_category_id uuid not null references location_category (id) +); + +alter table location_category_mapping + enable row level security; + +create policy "location_category_mapping is viewable by everyone" + on location_category_mapping for select + to authenticated, anon + using (true); diff --git a/supabase/migrations/20240520215626_create_location_schedule.sql b/supabase/migrations/20240520215626_create_location_schedule.sql index d45725c..eab296a 100644 --- a/supabase/migrations/20240520215626_create_location_schedule.sql +++ b/supabase/migrations/20240520215626_create_location_schedule.sql @@ -16,9 +16,28 @@ create table location_schedule when location is null then location_category is not null end) ); -alter table location_schedule enable row level security; +alter table location_schedule + enable row level security; create policy "location_schedule is viewable by everyone" -on location_schedule for select -to authenticated, anon -using ( true ); + on location_schedule for select + to authenticated, anon + using (true); + +create table location_schedule_timetable +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id), + location_schedule_id uuid not null references location_schedule (id), + days text not null, + open_at time not null, + open_for interval minute not null +); + +alter table location_schedule_timetable + enable row level security; + +create policy "location_schedule_timetable is viewable by everyone" + on location_schedule_timetable for select + to authenticated, anon + using (true); diff --git a/supabase/migrations/20240520215627_create_location_schedule_timetable.sql b/supabase/migrations/20240520215627_create_location_schedule_timetable.sql deleted file mode 100644 index f4cc3df..0000000 --- a/supabase/migrations/20240520215627_create_location_schedule_timetable.sql +++ /dev/null @@ -1,16 +0,0 @@ -create table location_schedule_timetable -( - id uuid not null default uuid_generate_v4() primary key, - source text not null references data_source (id), - location_schedule_id uuid not null references location_schedule (id), - days text not null, - open_at time not null, - open_for interval minute not null -); - -alter table location_schedule_timetable enable row level security; - -create policy "location_schedule_timetable is viewable by everyone" -on location_schedule_timetable for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215628_create_directory_entry.sql b/supabase/migrations/20240520215628_create_directory_entry.sql index 4946e42..cb2d948 100644 --- a/supabase/migrations/20240520215628_create_directory_entry.sql +++ b/supabase/migrations/20240520215628_create_directory_entry.sql @@ -17,9 +17,68 @@ create table directory_entry specialties text ); -alter table directory_entry enable row level security; +alter table directory_entry + enable row level security; create policy "directory_entry is viewable by everyone" -on directory_entry for select -to authenticated, anon -using ( true ); + on directory_entry for select + to authenticated, anon + using (true); + +-- TODO: what is this for, again? +create table directory_entry_category +( + directory_entry uuid references directory_entry (id) on update cascade on delete cascade, + category text not null check (length(trim(category)) > 0) +); + +alter table directory_entry_category + enable row level security; + +create policy "directory_entry_category is viewable by everyone" + on directory_entry_category for select + to authenticated, anon + using (true); + +create table directory_entry_location +( + directory_entry uuid not null references directory_entry (id) on update cascade on delete cascade, + location uuid not null references location (id) on update cascade on delete cascade, + source text not null references data_source (id) on update cascade on delete cascade, + title text, + email text, + phone text, + fax text, + hours text, -- can we use a schedule record for this? probably not... + description text +); + +alter table directory_entry_location + enable row level security; + +create policy "directory_entry_location is viewable by everyone" + on directory_entry_location for select + to authenticated, anon + using (true); + +create table directory_entry_organization +( + directory_entry uuid not null references directory_entry (id) on update cascade on delete cascade, + directory_organization uuid not null references directory_entry (id) on update cascade on delete cascade, + source text not null references data_source (id) on update cascade on delete cascade, + role text, -- not sure if needed, or if can be replaced with title + title text, + email text, + phone text, + fax text, + hours text, -- can we use a schedule record for this? probably not... + description text +); + +alter table directory_entry_organization + enable row level security; + +create policy "directory_entry_organization is viewable by everyone" + on directory_entry_organization for select + to authenticated, anon + using (true); diff --git a/supabase/migrations/20240520215629_create_directory_entry_category.sql b/supabase/migrations/20240520215629_create_directory_entry_category.sql deleted file mode 100644 index dcd88c9..0000000 --- a/supabase/migrations/20240520215629_create_directory_entry_category.sql +++ /dev/null @@ -1,13 +0,0 @@ --- TODO: what is this for, again? -create table directory_entry_category -( - directory_entry uuid references directory_entry (id) on update cascade on delete cascade, - category text not null check (length(trim(category)) > 0) -); - -alter table directory_entry_category enable row level security; - -create policy "directory_entry_category is viewable by everyone" -on directory_entry_category for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215630_create_directory_entry_location.sql b/supabase/migrations/20240520215630_create_directory_entry_location.sql deleted file mode 100644 index adb58fb..0000000 --- a/supabase/migrations/20240520215630_create_directory_entry_location.sql +++ /dev/null @@ -1,19 +0,0 @@ -create table directory_entry_location -( - directory_entry uuid not null references directory_entry (id) on update cascade on delete cascade, - location uuid not null references location (id) on update cascade on delete cascade, - source text not null references data_source (id) on update cascade on delete cascade, - title text, - email text, - phone text, - fax text, - hours text, -- can we use a schedule record for this? probably not... - description text -); - -alter table directory_entry_location enable row level security; - -create policy "directory_entry_location is viewable by everyone" -on directory_entry_location for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215631_create_directory_entry_organization.sql b/supabase/migrations/20240520215631_create_directory_entry_organization.sql deleted file mode 100644 index 15f4bc8..0000000 --- a/supabase/migrations/20240520215631_create_directory_entry_organization.sql +++ /dev/null @@ -1,20 +0,0 @@ -create table directory_entry_organization -( - directory_entry uuid not null references directory_entry (id) on update cascade on delete cascade, - directory_organization uuid not null references directory_entry (id) on update cascade on delete cascade, - source text not null references data_source (id) on update cascade on delete cascade, - role text, -- not sure if needed, or if can be replaced with title - title text, - email text, - phone text, - fax text, - hours text, -- can we use a schedule record for this? probably not... - description text -); - -alter table directory_entry_organization enable row level security; - -create policy "directory_entry_organization is viewable by everyone" -on directory_entry_organization for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215632_create_content_category.sql b/supabase/migrations/20240520215632_create_content_category.sql index 69b6df7..8843866 100644 --- a/supabase/migrations/20240520215632_create_content_category.sql +++ b/supabase/migrations/20240520215632_create_content_category.sql @@ -5,9 +5,10 @@ create table content_category sort_title text null unique check (length(sort_title) between 0 and 256) ); -alter table content_category enable row level security; +alter table content_category + enable row level security; create policy "content_category is viewable by everyone" -on content_category for select -to authenticated, anon -using ( true ); + on content_category for select + to authenticated, anon + using (true); diff --git a/supabase/migrations/20240520215633_create_calendar_event.sql b/supabase/migrations/20240520215633_create_calendar_event.sql index acd2e94..83051fc 100644 --- a/supabase/migrations/20240520215633_create_calendar_event.sql +++ b/supabase/migrations/20240520215633_create_calendar_event.sql @@ -15,9 +15,45 @@ create table calendar_event constraint only_one_location check ( case when campus_location_id is not null then textual_location is null end ) ); -alter table calendar_event enable row level security; +alter table calendar_event + enable row level security; create policy "calendar_event is viewable by everyone" -on calendar_event for select -to authenticated, anon -using ( true ); + on calendar_event for select + to authenticated, anon + using (true); + +create table calendar_event_category +( + calendar_event_id uuid not null references calendar_event (id) on update cascade on delete cascade, + category_id uuid not null references content_category (id) on update cascade on delete cascade, + source text not null references data_source (id) on update cascade on delete cascade, + primary key (calendar_event_id, category_id) +); + +alter table calendar_event_category + enable row level security; + +create policy "calendar_event_category is viewable by everyone" + on calendar_event_category for select + to authenticated, anon + using (true); + +create table calendar_event_link +( + calendar_event_id uuid not null references calendar_event (id) on update cascade on delete cascade, + source text not null references data_source (id) on update cascade on delete cascade, + href text not null, + title text not null, + content_type text, + link_mode text not null check (link_mode in ('a', 'stream')), + primary key (calendar_event_id, href) +); + +alter table calendar_event_link + enable row level security; + +create policy "calendar_event_link is viewable by everyone" + on calendar_event_link for select + to authenticated, anon + using (true); diff --git a/supabase/migrations/20240520215634_create_calendar_event_category.sql b/supabase/migrations/20240520215634_create_calendar_event_category.sql deleted file mode 100644 index 1004d35..0000000 --- a/supabase/migrations/20240520215634_create_calendar_event_category.sql +++ /dev/null @@ -1,14 +0,0 @@ -create table calendar_event_category -( - calendar_event_id uuid not null references calendar_event (id) on update cascade on delete cascade, - category_id uuid not null references content_category (id) on update cascade on delete cascade, - source text not null references data_source (id) on update cascade on delete cascade, - primary key (calendar_event_id, category_id) -); - -alter table calendar_event_category enable row level security; - -create policy "calendar_event_category is viewable by everyone" -on calendar_event_category for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215635_create_calendar_event_link.sql b/supabase/migrations/20240520215635_create_calendar_event_link.sql deleted file mode 100644 index 8323b49..0000000 --- a/supabase/migrations/20240520215635_create_calendar_event_link.sql +++ /dev/null @@ -1,17 +0,0 @@ -create table calendar_event_link -( - calendar_event_id uuid not null references calendar_event (id) on update cascade on delete cascade, - source text not null references data_source (id) on update cascade on delete cascade, - href text not null, - title text not null, - content_type text, - link_mode text not null check (link_mode in ('a', 'stream')), - primary key (calendar_event_id, href) -); - -alter table calendar_event_link enable row level security; - -create policy "calendar_event_link is viewable by everyone" -on calendar_event_link for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215636_create_feed.sql b/supabase/migrations/20240520215636_create_feed.sql index b90e69b..1f4fed0 100644 --- a/supabase/migrations/20240520215636_create_feed.sql +++ b/supabase/migrations/20240520215636_create_feed.sql @@ -6,9 +6,49 @@ create table feed primary key (uri) ); -alter table feed enable row level security; +alter table feed + enable row level security; create policy "feed is viewable by everyone" -on feed for select -to authenticated, anon -using ( true ); + on feed for select + to authenticated, anon + using (true); + +create table feed_article +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + published_at timestamptz not null, + updated_at timestamptz null, + title text not null check (length(title) > 0), + body text not null default '', + thumbnail_uri text null, + banner_uri text null, + sponsoring_entity uuid null references directory_entry (id) on update cascade on delete set null, + campus_location_id uuid null references location (id) on update cascade on delete set null, + textual_location text null, + constraint only_one_location check ( case when campus_location_id is not null then textual_location is null end ) +); + +alter table feed_article + enable row level security; + +create policy "feed_article is viewable by everyone" + on feed_article for select + to authenticated, anon + using (true); + +create table feed_article_category +( + feed_article_id uuid not null references feed_article (id) on update cascade on delete cascade, + category_id uuid not null references content_category (id) on update cascade on delete cascade, + primary key (feed_article_id, category_id) +); + +alter table feed_article_category + enable row level security; + +create policy "feed_article_category is viewable by everyone" + on feed_article_category for select + to authenticated, anon + using (true); diff --git a/supabase/migrations/20240520215637_create_feed_article.sql b/supabase/migrations/20240520215637_create_feed_article.sql deleted file mode 100644 index f6a1e2e..0000000 --- a/supabase/migrations/20240520215637_create_feed_article.sql +++ /dev/null @@ -1,22 +0,0 @@ -create table feed_article -( - id uuid not null default uuid_generate_v4() primary key, - source text not null references data_source (id) on update cascade on delete cascade, - published_at timestamptz not null, - updated_at timestamptz null, - title text not null check (length(title) > 0), - body text not null default '', - thumbnail_uri text null, - banner_uri text null, - sponsoring_entity uuid null references directory_entry (id) on update cascade on delete set null, - campus_location_id uuid null references location (id) on update cascade on delete set null, - textual_location text null, - constraint only_one_location check ( case when campus_location_id is not null then textual_location is null end ) -); - -alter table feed_article enable row level security; - -create policy "feed_article is viewable by everyone" -on feed_article for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215638_create_feed_article_category.sql b/supabase/migrations/20240520215638_create_feed_article_category.sql deleted file mode 100644 index 7d527af..0000000 --- a/supabase/migrations/20240520215638_create_feed_article_category.sql +++ /dev/null @@ -1,13 +0,0 @@ -create table feed_article_category -( - feed_article_id uuid not null references feed_article (id) on update cascade on delete cascade, - category_id uuid not null references content_category (id) on update cascade on delete cascade, - primary key (feed_article_id, category_id) -); - -alter table feed_article_category enable row level security; - -create policy "feed_article_category is viewable by everyone" -on feed_article_category for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215639_create_app_notice.sql b/supabase/migrations/20240520215639_create_app_notice.sql index e435774..815906f 100644 --- a/supabase/migrations/20240520215639_create_app_notice.sql +++ b/supabase/migrations/20240520215639_create_app_notice.sql @@ -13,9 +13,10 @@ create table app_notice platform text null ); -alter table app_notice enable row level security; +alter table app_notice + enable row level security; create policy "app_notice is viewable by everyone" -on app_notice for select -to authenticated, anon -using ( true ); + on app_notice for select + to authenticated, anon + using (true); diff --git a/supabase/migrations/20240520215640_create_livestream.sql b/supabase/migrations/20240520215640_create_livestream.sql index d0622d6..d35c10a 100644 --- a/supabase/migrations/20240520215640_create_livestream.sql +++ b/supabase/migrations/20240520215640_create_livestream.sql @@ -14,9 +14,10 @@ create table livestream website text null ); -alter table livestream enable row level security; +alter table livestream + enable row level security; create policy "livestream is viewable by everyone" -on livestream for select -to authenticated, anon -using ( true ); + on livestream for select + to authenticated, anon + using (true); diff --git a/supabase/migrations/20240520215641_create_bus_route.sql b/supabase/migrations/20240520215641_create_bus_route.sql index 3828bf8..04e24c8 100644 --- a/supabase/migrations/20240520215641_create_bus_route.sql +++ b/supabase/migrations/20240520215641_create_bus_route.sql @@ -6,9 +6,63 @@ create table bus_route title text not null ); -alter table bus_route enable row level security; +alter table bus_route + enable row level security; create policy "bus_route is viewable by everyone" -on bus_route for select -to authenticated, anon -using ( true ); + on bus_route for select + to authenticated, anon + using (true); + +create table bus_route_stop +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + name text not null, + coordinates jsonb not null default '[]'::jsonb +); + +alter table bus_route_stop + enable row level security; + +create policy "bus_route_stop is viewable by everyone" + on bus_route_stop for select + to authenticated, anon + using (true); + +create table bus_route_timetable +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + inbound_stop uuid null references bus_route_stop (id), + inbound_time time null, + outbound_stop uuid null references bus_route_stop (id), + outbound_time time null, + constraint inbound_time_if_stop check (case when inbound_stop is not null then inbound_time is not null end), + constraint outbound_time_if_stop check (case when outbound_stop is not null then outbound_time is not null end) +); + +alter table bus_route_timetable + enable row level security; + +create policy "bus_route_timetable is viewable by everyone" + on bus_route_timetable for select + to authenticated, anon + using (true); + +create table bus_route_schedule +( + bus_route_id uuid not null references bus_route (id) on update cascade on delete restrict, + timetable_id uuid not null references bus_route_timetable (id) on update cascade on delete restrict, + source text not null references data_source (id) on update cascade on delete cascade, + active_from timestamptz null, + active_until timestamptz null +); + +alter table bus_route_schedule + enable row level security; + +create policy "bus_route_schedule is viewable by everyone" + on bus_route_schedule for select + to authenticated, anon + using (true); diff --git a/supabase/migrations/20240520215642_create_bus_route_stop.sql b/supabase/migrations/20240520215642_create_bus_route_stop.sql deleted file mode 100644 index a31d49d..0000000 --- a/supabase/migrations/20240520215642_create_bus_route_stop.sql +++ /dev/null @@ -1,14 +0,0 @@ -create table bus_route_stop -( - id uuid not null default uuid_generate_v4() primary key, - source text not null references data_source (id) on update cascade on delete cascade, - name text not null, - coordinates jsonb not null default '[]'::jsonb -); - -alter table bus_route_stop enable row level security; - -create policy "bus_route_stop is viewable by everyone" -on bus_route_stop for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215643_create_bus_route_timetable.sql b/supabase/migrations/20240520215643_create_bus_route_timetable.sql deleted file mode 100644 index 885b318..0000000 --- a/supabase/migrations/20240520215643_create_bus_route_timetable.sql +++ /dev/null @@ -1,18 +0,0 @@ -create table bus_route_timetable -( - id uuid not null default uuid_generate_v4() primary key, - source text not null references data_source (id) on update cascade on delete cascade, - inbound_stop uuid null references bus_route_stop (id), - inbound_time time null, - outbound_stop uuid null references bus_route_stop (id), - outbound_time time null, - constraint inbound_time_if_stop check (case when inbound_stop is not null then inbound_time is not null end), - constraint outbound_time_if_stop check (case when outbound_stop is not null then outbound_time is not null end) -); - -alter table bus_route_timetable enable row level security; - -create policy "bus_route_timetable is viewable by everyone" -on bus_route_timetable for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215644_create_bus_route_schedule.sql b/supabase/migrations/20240520215644_create_bus_route_schedule.sql deleted file mode 100644 index b8d468c..0000000 --- a/supabase/migrations/20240520215644_create_bus_route_schedule.sql +++ /dev/null @@ -1,15 +0,0 @@ -create table bus_route_schedule -( - bus_route_id uuid not null references bus_route (id) on update cascade on delete restrict, - timetable_id uuid not null references bus_route_timetable (id) on update cascade on delete restrict, - source text not null references data_source (id) on update cascade on delete cascade, - active_from timestamptz null, - active_until timestamptz null -); - -alter table bus_route_schedule enable row level security; - -create policy "bus_route_schedule is viewable by everyone" -on bus_route_schedule for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215645_create_cafe.sql b/supabase/migrations/20240520215645_create_cafe.sql index e776d8f..fcdf097 100644 --- a/supabase/migrations/20240520215645_create_cafe.sql +++ b/supabase/migrations/20240520215645_create_cafe.sql @@ -7,9 +7,110 @@ create table cafe location uuid null references location (id) ); -alter table cafe enable row level security; +alter table cafe + enable row level security; create policy "cafe is viewable by everyone" -on cafe for select -to authenticated, anon -using ( true ); + on cafe for select + to authenticated, anon + using (true); + +create table cafe_cor +( + id text not null primary key, + title text not null, + description text not null, + icon_uri text not null +); + +alter table cafe_cor + enable row level security; + +create policy "cafe_cor is viewable by everyone" + on cafe_cor for select + to authenticated, anon + using (true); + +create table cafe_item +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + title text not null, + description text, + rating decimal, + monotony jsonb not null default '{}'::jsonb, -- TODO: expand this into a table + nutrition jsonb not null default '{}'::jsonb -- TODO: expand this into a table +); + +alter table cafe_item + enable row level security; + +create policy "cafe_item is viewable by everyone" + on cafe_item for select + to authenticated, anon + using (true); + +create table cafe_item_variation +( + cafe_item_id uuid not null references cafe_item (id), + title text not null, + description text +); + +alter table cafe_item_variation + enable row level security; + +create policy "cafe_item_variation is viewable by everyone" + on cafe_item_variation for select + to authenticated, anon + using (true); + +create table cafe_item_cor +( + cafe_item_id uuid not null references cafe_item (id), + cafe_cor_id text not null references cafe_cor (id), + primary key (cafe_item_id, cafe_cor_id) +); + +alter table cafe_item_cor + enable row level security; + +create policy "cafe_item_cor is viewable by everyone" + on cafe_item_cor for select + to authenticated, anon + using (true); + +create table cafe_station_menu +( + id uuid not null default uuid_generate_v4() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + station_title text not null, + station_note text null, + station_sort_order integer not null, + item_id uuid not null references cafe_item (id) on update cascade on delete cascade, + item_sort_order integer not null, + is_featured bool not null default false +); + +alter table cafe_station_menu + enable row level security; + +create policy "cafe_station_menu is viewable by everyone" + on cafe_station_menu for select + to authenticated, anon + using (true); + +create table cafe_menu_schedule +( + schedule_id uuid not null references location_schedule (id), + station_id uuid not null references cafe_station_menu (id), + primary key (schedule_id, station_id) +); + +alter table cafe_menu_schedule + enable row level security; + +create policy "cafe_menu_schedule is viewable by everyone" + on cafe_menu_schedule for select + to authenticated, anon + using (true); diff --git a/supabase/migrations/20240520215646_create_cafe_cor.sql b/supabase/migrations/20240520215646_create_cafe_cor.sql deleted file mode 100644 index f15fee5..0000000 --- a/supabase/migrations/20240520215646_create_cafe_cor.sql +++ /dev/null @@ -1,15 +0,0 @@ - -create table cafe_cor -( - id text not null primary key, - title text not null, - description text not null, - icon_uri text not null -); - -alter table cafe_cor enable row level security; - -create policy "cafe_cor is viewable by everyone" -on cafe_cor for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215647_create_cafe_item.sql b/supabase/migrations/20240520215647_create_cafe_item.sql deleted file mode 100644 index 6407f75..0000000 --- a/supabase/migrations/20240520215647_create_cafe_item.sql +++ /dev/null @@ -1,18 +0,0 @@ - -create table cafe_item -( - id uuid not null default uuid_generate_v4() primary key, - source text not null references data_source (id) on update cascade on delete cascade, - title text not null, - description text, - rating decimal, - monotony jsonb not null default '{}'::jsonb, -- TODO: expand this into a table - nutrition jsonb not null default '{}'::jsonb -- TODO: expand this into a table -); - -alter table cafe_item enable row level security; - -create policy "cafe_item is viewable by everyone" -on cafe_item for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215648_create_cafe_item_variation.sql b/supabase/migrations/20240520215648_create_cafe_item_variation.sql deleted file mode 100644 index 5a977ea..0000000 --- a/supabase/migrations/20240520215648_create_cafe_item_variation.sql +++ /dev/null @@ -1,14 +0,0 @@ - -create table cafe_item_variation -( - cafe_item_id uuid not null references cafe_item (id), - title text not null, - description text -); - -alter table cafe_item_variation enable row level security; - -create policy "cafe_item_variation is viewable by everyone" -on cafe_item_variation for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215649_create_cafe_item_cor.sql b/supabase/migrations/20240520215649_create_cafe_item_cor.sql deleted file mode 100644 index e698a89..0000000 --- a/supabase/migrations/20240520215649_create_cafe_item_cor.sql +++ /dev/null @@ -1,14 +0,0 @@ - -create table cafe_item_cor -( - cafe_item_id uuid not null references cafe_item (id), - cafe_cor_id text not null references cafe_cor (id), - primary key (cafe_item_id, cafe_cor_id) -); - -alter table cafe_item_cor enable row level security; - -create policy "cafe_item_cor is viewable by everyone" -on cafe_item_cor for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215650_create_cafe_station_menu.sql b/supabase/migrations/20240520215650_create_cafe_station_menu.sql deleted file mode 100644 index e367d6a..0000000 --- a/supabase/migrations/20240520215650_create_cafe_station_menu.sql +++ /dev/null @@ -1,19 +0,0 @@ - -create table cafe_station_menu -( - id uuid not null default uuid_generate_v4() primary key, - source text not null references data_source (id) on update cascade on delete cascade, - station_title text not null, - station_note text null, - station_sort_order integer not null, - item_id uuid not null references cafe_item (id) on update cascade on delete cascade, - item_sort_order integer not null, - is_featured bool not null default false -); - -alter table cafe_station_menu enable row level security; - -create policy "cafe_station_menu is viewable by everyone" -on cafe_station_menu for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215651_create_cafe_menu_schedule.sql b/supabase/migrations/20240520215651_create_cafe_menu_schedule.sql deleted file mode 100644 index d506b43..0000000 --- a/supabase/migrations/20240520215651_create_cafe_menu_schedule.sql +++ /dev/null @@ -1,14 +0,0 @@ - -create table cafe_menu_schedule -( - schedule_id uuid not null references location_schedule (id), - station_id uuid not null references cafe_station_menu (id), - primary key (schedule_id, station_id) -); - -alter table cafe_menu_schedule enable row level security; - -create policy "cafe_menu_schedule is viewable by everyone" -on cafe_menu_schedule for select -to authenticated, anon -using ( true ); diff --git a/supabase/migrations/20240520215652_create_student_work.sql b/supabase/migrations/20240520215652_create_student_work.sql index 9b90c27..1d1eea3 100644 --- a/supabase/migrations/20240520215652_create_student_work.sql +++ b/supabase/migrations/20240520215652_create_student_work.sql @@ -1,4 +1,3 @@ - create table student_work ( id uuid not null default uuid_generate_v4() primary key, @@ -20,9 +19,10 @@ create table student_work when department_name is null then department_id is not null end) ); -alter table student_work enable row level security; +alter table student_work + enable row level security; create policy "student_work is viewable by everyone" -on student_work for select -to authenticated, anon -using ( true ); + on student_work for select + to authenticated, anon + using (true); From 61c9eda4978d8f5d43d8ae92a2472d371f80aea6 Mon Sep 17 00:00:00 2001 From: Hawken Rives Date: Tue, 21 May 2024 20:40:37 -0400 Subject: [PATCH 09/14] redo access patterns --- .../20240520215620_create_data_source.sql | 9 ++-- .../migrations/20240520215621_create_link.sql | 5 +- .../20240520215622_create_dictionary.sql | 5 +- .../20240520215623_create_metadata.sql | 5 +- .../20240520215625_create_location.sql | 46 +++++++++--------- ...0240520215626_create_location_schedule.sql | 12 ++--- .../20240520215628_create_directory_entry.sql | 27 ++++++----- ...20240520215632_create_content_category.sql | 5 +- .../20240520215633_create_calendar_event.sql | 19 ++++---- .../migrations/20240520215636_create_feed.sql | 19 ++++---- .../20240520215639_create_app_notice.sql | 5 +- .../20240520215640_create_livestream.sql | 5 +- .../20240520215641_create_bus_route.sql | 26 +++++----- .../migrations/20240520215645_create_cafe.sql | 47 ++++++++++--------- .../20240520215652_create_student_work.sql | 5 +- 15 files changed, 120 insertions(+), 120 deletions(-) diff --git a/supabase/migrations/20240520215620_create_data_source.sql b/supabase/migrations/20240520215620_create_data_source.sql index 9e0b27c..a845d9d 100644 --- a/supabase/migrations/20240520215620_create_data_source.sql +++ b/supabase/migrations/20240520215620_create_data_source.sql @@ -6,15 +6,12 @@ create table data_source ); comment on table data_source is 'the authoritative list of data sources, including manual data entry'; - comment on column data_source.type is 'what type of source is this?'; - -comment on column data_source.uri is 'where did we start this scrape from?'; +comment on column data_source.uri is 'where did we start this scrape from, or which URL do we load to fetch the data?'; alter table data_source enable row level security; -create policy "data_source is viewable by everyone" +create policy "Enable read access for all users" on data_source for select - to authenticated, - anon using (true); + to public using (true); diff --git a/supabase/migrations/20240520215621_create_link.sql b/supabase/migrations/20240520215621_create_link.sql index 9cc69ed..077d570 100644 --- a/supabase/migrations/20240520215621_create_link.sql +++ b/supabase/migrations/20240520215621_create_link.sql @@ -18,7 +18,6 @@ create table link alter table link enable row level security; -create policy "link is viewable by everyone" +create policy "Enable read access for all users" on link for select - to authenticated, anon - using (true); + to public using (true); diff --git a/supabase/migrations/20240520215622_create_dictionary.sql b/supabase/migrations/20240520215622_create_dictionary.sql index 2111589..b87e382 100644 --- a/supabase/migrations/20240520215622_create_dictionary.sql +++ b/supabase/migrations/20240520215622_create_dictionary.sql @@ -16,7 +16,6 @@ create table dictionary alter table dictionary enable row level security; -create policy "dictionary is viewable by everyone" +create policy "Enable read access for all users" on dictionary for select - to authenticated, anon - using (true); + to public using (true); diff --git a/supabase/migrations/20240520215623_create_metadata.sql b/supabase/migrations/20240520215623_create_metadata.sql index 2f8a383..64df90b 100644 --- a/supabase/migrations/20240520215623_create_metadata.sql +++ b/supabase/migrations/20240520215623_create_metadata.sql @@ -9,7 +9,6 @@ create table metadata alter table metadata enable row level security; -create policy "metadata is viewable by everyone" +create policy "Enable read access for all users" on metadata for select - to authenticated, anon - using (true); + to public using (true); diff --git a/supabase/migrations/20240520215625_create_location.sql b/supabase/migrations/20240520215625_create_location.sql index 0a114d9..9d4cd72 100644 --- a/supabase/migrations/20240520215625_create_location.sql +++ b/supabase/migrations/20240520215625_create_location.sql @@ -1,25 +1,8 @@ -create table location_category -( - id uuid not null default uuid_generate_v4() primary key, - title text not null unique check (length(title) between 0 and 256), - sort_title text unique check (length(sort_title) between 0 and 256), - source text not null references data_source (id) on update cascade on delete cascade -); - -alter table location_category - enable row level security; - -create policy "location_category is viewable by everyone" - on location_category for select - to authenticated, anon - using (true); - create table location ( id uuid not null default uuid_generate_v4() primary key, source text not null default 'manual', within uuid references location (id) on update cascade on delete restrict, - category uuid not null references location_category (id) on update cascade on delete restrict, -- TODO: keep as 1-1, or allow multiple? title text not null default '', subtitle text not null default '', abbreviation text not null default '', @@ -37,10 +20,28 @@ create table location alter table location enable row level security; -create policy "location is viewable by everyone" +create policy "Enable read access for all users" on location for select - to authenticated, anon - using (true); + to public using (true); + +--- + +create table location_category +( + id uuid not null default uuid_generate_v4() primary key, + title text not null unique check (length(title) between 0 and 256), + sort_title text unique check (length(sort_title) between 0 and 256), + source text not null references data_source (id) on update cascade on delete cascade +); + +alter table location_category + enable row level security; + +create policy "Enable read access for all users" + on location_category for select + to public using (true); + +--- create table location_category_mapping ( @@ -51,7 +52,6 @@ create table location_category_mapping alter table location_category_mapping enable row level security; -create policy "location_category_mapping is viewable by everyone" +create policy "Enable read access for all users" on location_category_mapping for select - to authenticated, anon - using (true); + to public using (true); diff --git a/supabase/migrations/20240520215626_create_location_schedule.sql b/supabase/migrations/20240520215626_create_location_schedule.sql index eab296a..9229b8a 100644 --- a/supabase/migrations/20240520215626_create_location_schedule.sql +++ b/supabase/migrations/20240520215626_create_location_schedule.sql @@ -19,10 +19,11 @@ create table location_schedule alter table location_schedule enable row level security; -create policy "location_schedule is viewable by everyone" +create policy "Enable read access for all users" on location_schedule for select - to authenticated, anon - using (true); + to public using (true); + +--- create table location_schedule_timetable ( @@ -37,7 +38,6 @@ create table location_schedule_timetable alter table location_schedule_timetable enable row level security; -create policy "location_schedule_timetable is viewable by everyone" +create policy "Enable read access for all users" on location_schedule_timetable for select - to authenticated, anon - using (true); + to public using (true); diff --git a/supabase/migrations/20240520215628_create_directory_entry.sql b/supabase/migrations/20240520215628_create_directory_entry.sql index cb2d948..3caeaa6 100644 --- a/supabase/migrations/20240520215628_create_directory_entry.sql +++ b/supabase/migrations/20240520215628_create_directory_entry.sql @@ -20,12 +20,12 @@ create table directory_entry alter table directory_entry enable row level security; -create policy "directory_entry is viewable by everyone" +create policy "Enable read access for all users" on directory_entry for select - to authenticated, anon - using (true); + to public using (true); + +--- --- TODO: what is this for, again? create table directory_entry_category ( directory_entry uuid references directory_entry (id) on update cascade on delete cascade, @@ -35,10 +35,11 @@ create table directory_entry_category alter table directory_entry_category enable row level security; -create policy "directory_entry_category is viewable by everyone" +create policy "Enable read access for all users" on directory_entry_category for select - to authenticated, anon - using (true); + to public using (true); + +--- create table directory_entry_location ( @@ -56,10 +57,11 @@ create table directory_entry_location alter table directory_entry_location enable row level security; -create policy "directory_entry_location is viewable by everyone" +create policy "Enable read access for all users" on directory_entry_location for select - to authenticated, anon - using (true); + to public using (true); + +--- create table directory_entry_organization ( @@ -78,7 +80,6 @@ create table directory_entry_organization alter table directory_entry_organization enable row level security; -create policy "directory_entry_organization is viewable by everyone" +create policy "Enable read access for all users" on directory_entry_organization for select - to authenticated, anon - using (true); + to public using (true); diff --git a/supabase/migrations/20240520215632_create_content_category.sql b/supabase/migrations/20240520215632_create_content_category.sql index 8843866..68712bd 100644 --- a/supabase/migrations/20240520215632_create_content_category.sql +++ b/supabase/migrations/20240520215632_create_content_category.sql @@ -8,7 +8,6 @@ create table content_category alter table content_category enable row level security; -create policy "content_category is viewable by everyone" +create policy "Enable read access for all users" on content_category for select - to authenticated, anon - using (true); + to public using (true); diff --git a/supabase/migrations/20240520215633_create_calendar_event.sql b/supabase/migrations/20240520215633_create_calendar_event.sql index 83051fc..a2162de 100644 --- a/supabase/migrations/20240520215633_create_calendar_event.sql +++ b/supabase/migrations/20240520215633_create_calendar_event.sql @@ -18,10 +18,11 @@ create table calendar_event alter table calendar_event enable row level security; -create policy "calendar_event is viewable by everyone" +create policy "Enable read access for all users" on calendar_event for select - to authenticated, anon - using (true); + to public using (true); + +--- create table calendar_event_category ( @@ -34,10 +35,11 @@ create table calendar_event_category alter table calendar_event_category enable row level security; -create policy "calendar_event_category is viewable by everyone" +create policy "Enable read access for all users" on calendar_event_category for select - to authenticated, anon - using (true); + to public using (true); + +--- create table calendar_event_link ( @@ -53,7 +55,6 @@ create table calendar_event_link alter table calendar_event_link enable row level security; -create policy "calendar_event_link is viewable by everyone" +create policy "Enable read access for all users" on calendar_event_link for select - to authenticated, anon - using (true); + to public using (true); diff --git a/supabase/migrations/20240520215636_create_feed.sql b/supabase/migrations/20240520215636_create_feed.sql index 1f4fed0..451af39 100644 --- a/supabase/migrations/20240520215636_create_feed.sql +++ b/supabase/migrations/20240520215636_create_feed.sql @@ -9,10 +9,11 @@ create table feed alter table feed enable row level security; -create policy "feed is viewable by everyone" +create policy "Enable read access for all users" on feed for select - to authenticated, anon - using (true); + to public using (true); + +--- create table feed_article ( @@ -33,10 +34,11 @@ create table feed_article alter table feed_article enable row level security; -create policy "feed_article is viewable by everyone" +create policy "Enable read access for all users" on feed_article for select - to authenticated, anon - using (true); + to public using (true); + +--- create table feed_article_category ( @@ -48,7 +50,6 @@ create table feed_article_category alter table feed_article_category enable row level security; -create policy "feed_article_category is viewable by everyone" +create policy "Enable read access for all users" on feed_article_category for select - to authenticated, anon - using (true); + to public using (true); diff --git a/supabase/migrations/20240520215639_create_app_notice.sql b/supabase/migrations/20240520215639_create_app_notice.sql index 815906f..5bd136c 100644 --- a/supabase/migrations/20240520215639_create_app_notice.sql +++ b/supabase/migrations/20240520215639_create_app_notice.sql @@ -16,7 +16,6 @@ create table app_notice alter table app_notice enable row level security; -create policy "app_notice is viewable by everyone" +create policy "Enable read access for all users" on app_notice for select - to authenticated, anon - using (true); + to public using (true); diff --git a/supabase/migrations/20240520215640_create_livestream.sql b/supabase/migrations/20240520215640_create_livestream.sql index d35c10a..8aedd1e 100644 --- a/supabase/migrations/20240520215640_create_livestream.sql +++ b/supabase/migrations/20240520215640_create_livestream.sql @@ -17,7 +17,6 @@ create table livestream alter table livestream enable row level security; -create policy "livestream is viewable by everyone" +create policy "Enable read access for all users" on livestream for select - to authenticated, anon - using (true); + to public using (true); diff --git a/supabase/migrations/20240520215641_create_bus_route.sql b/supabase/migrations/20240520215641_create_bus_route.sql index 04e24c8..dbd32ac 100644 --- a/supabase/migrations/20240520215641_create_bus_route.sql +++ b/supabase/migrations/20240520215641_create_bus_route.sql @@ -9,10 +9,11 @@ create table bus_route alter table bus_route enable row level security; -create policy "bus_route is viewable by everyone" +create policy "Enable read access for all users" on bus_route for select - to authenticated, anon - using (true); + to public using (true); + +--- create table bus_route_stop ( @@ -25,10 +26,11 @@ create table bus_route_stop alter table bus_route_stop enable row level security; -create policy "bus_route_stop is viewable by everyone" +create policy "Enable read access for all users" on bus_route_stop for select - to authenticated, anon - using (true); + to public using (true); + +--- create table bus_route_timetable ( @@ -45,10 +47,11 @@ create table bus_route_timetable alter table bus_route_timetable enable row level security; -create policy "bus_route_timetable is viewable by everyone" +create policy "Enable read access for all users" on bus_route_timetable for select - to authenticated, anon - using (true); + to public using (true); + +--- create table bus_route_schedule ( @@ -62,7 +65,6 @@ create table bus_route_schedule alter table bus_route_schedule enable row level security; -create policy "bus_route_schedule is viewable by everyone" +create policy "Enable read access for all users" on bus_route_schedule for select - to authenticated, anon - using (true); + to public using (true); diff --git a/supabase/migrations/20240520215645_create_cafe.sql b/supabase/migrations/20240520215645_create_cafe.sql index fcdf097..842435f 100644 --- a/supabase/migrations/20240520215645_create_cafe.sql +++ b/supabase/migrations/20240520215645_create_cafe.sql @@ -10,10 +10,11 @@ create table cafe alter table cafe enable row level security; -create policy "cafe is viewable by everyone" +create policy "Enable read access for all users" on cafe for select - to authenticated, anon - using (true); + to public using (true); + +--- create table cafe_cor ( @@ -26,10 +27,11 @@ create table cafe_cor alter table cafe_cor enable row level security; -create policy "cafe_cor is viewable by everyone" +create policy "Enable read access for all users" on cafe_cor for select - to authenticated, anon - using (true); + to public using (true); + +--- create table cafe_item ( @@ -45,10 +47,11 @@ create table cafe_item alter table cafe_item enable row level security; -create policy "cafe_item is viewable by everyone" +create policy "Enable read access for all users" on cafe_item for select - to authenticated, anon - using (true); + to public using (true); + +--- create table cafe_item_variation ( @@ -60,10 +63,11 @@ create table cafe_item_variation alter table cafe_item_variation enable row level security; -create policy "cafe_item_variation is viewable by everyone" +create policy "Enable read access for all users" on cafe_item_variation for select - to authenticated, anon - using (true); + to public using (true); + +--- create table cafe_item_cor ( @@ -75,10 +79,11 @@ create table cafe_item_cor alter table cafe_item_cor enable row level security; -create policy "cafe_item_cor is viewable by everyone" +create policy "Enable read access for all users" on cafe_item_cor for select - to authenticated, anon - using (true); + to public using (true); + +--- create table cafe_station_menu ( @@ -95,10 +100,11 @@ create table cafe_station_menu alter table cafe_station_menu enable row level security; -create policy "cafe_station_menu is viewable by everyone" +create policy "Enable read access for all users" on cafe_station_menu for select - to authenticated, anon - using (true); + to public using (true); + +--- create table cafe_menu_schedule ( @@ -110,7 +116,6 @@ create table cafe_menu_schedule alter table cafe_menu_schedule enable row level security; -create policy "cafe_menu_schedule is viewable by everyone" +create policy "Enable read access for all users" on cafe_menu_schedule for select - to authenticated, anon - using (true); + to public using (true); \ No newline at end of file diff --git a/supabase/migrations/20240520215652_create_student_work.sql b/supabase/migrations/20240520215652_create_student_work.sql index 1d1eea3..c5b2db4 100644 --- a/supabase/migrations/20240520215652_create_student_work.sql +++ b/supabase/migrations/20240520215652_create_student_work.sql @@ -22,7 +22,6 @@ create table student_work alter table student_work enable row level security; -create policy "student_work is viewable by everyone" +create policy "Enable read access for all users" on student_work for select - to authenticated, anon - using (true); + to public using (true); From bc214b679aa524fd21b11f97dae4c37d9c227d97 Mon Sep 17 00:00:00 2001 From: Hawken Rives Date: Tue, 21 May 2024 20:40:50 -0400 Subject: [PATCH 10/14] create a new role for importing data --- .../20240521173139_create_data_admin_role.sql | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 supabase/migrations/20240521173139_create_data_admin_role.sql diff --git a/supabase/migrations/20240521173139_create_data_admin_role.sql b/supabase/migrations/20240521173139_create_data_admin_role.sql new file mode 100644 index 0000000..75f5e4c --- /dev/null +++ b/supabase/migrations/20240521173139_create_data_admin_role.sql @@ -0,0 +1,35 @@ +create role data_admin; + +create policy "Enable write access for data_admin bot" on app_notice for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on bus_route for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on bus_route_schedule for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on bus_route_stop for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on bus_route_timetable for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on cafe for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on cafe_cor for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on cafe_item for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on cafe_item_cor for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on cafe_item_variation for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on cafe_menu_schedule for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on cafe_station_menu for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on calendar_event for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on calendar_event_category for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on calendar_event_link for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on content_category for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on data_source for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on dictionary for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on directory_entry for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on directory_entry_category for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on directory_entry_location for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on directory_entry_organization for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on feed for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on feed_article for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on feed_article_category for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on link for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on livestream for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on location for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on location_category for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on location_schedule for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on location_schedule_timetable for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on metadata for all to data_admin using (true); +create policy "Enable write access for data_admin bot" on student_work for all to data_admin using (true); From e5a9d7efde717d9be5f7b686fbe54c37c41c5b17 Mon Sep 17 00:00:00 2001 From: Hawken Rives Date: Tue, 21 May 2024 20:42:32 -0400 Subject: [PATCH 11/14] use built-in uuid generator --- supabase/migrations/20240520215622_create_dictionary.sql | 2 +- supabase/migrations/20240520215625_create_location.sql | 4 ++-- .../migrations/20240520215626_create_location_schedule.sql | 4 ++-- .../migrations/20240520215628_create_directory_entry.sql | 2 +- .../migrations/20240520215632_create_content_category.sql | 2 +- .../migrations/20240520215633_create_calendar_event.sql | 2 +- supabase/migrations/20240520215636_create_feed.sql | 2 +- supabase/migrations/20240520215639_create_app_notice.sql | 2 +- supabase/migrations/20240520215640_create_livestream.sql | 2 +- supabase/migrations/20240520215641_create_bus_route.sql | 6 +++--- supabase/migrations/20240520215645_create_cafe.sql | 6 +++--- supabase/migrations/20240520215652_create_student_work.sql | 2 +- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/supabase/migrations/20240520215622_create_dictionary.sql b/supabase/migrations/20240520215622_create_dictionary.sql index b87e382..1e349ff 100644 --- a/supabase/migrations/20240520215622_create_dictionary.sql +++ b/supabase/migrations/20240520215622_create_dictionary.sql @@ -1,6 +1,6 @@ create table dictionary ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, uri text not null default '', title text not null check (length(title) < 1024), diff --git a/supabase/migrations/20240520215625_create_location.sql b/supabase/migrations/20240520215625_create_location.sql index 9d4cd72..aa89cc0 100644 --- a/supabase/migrations/20240520215625_create_location.sql +++ b/supabase/migrations/20240520215625_create_location.sql @@ -1,6 +1,6 @@ create table location ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null default 'manual', within uuid references location (id) on update cascade on delete restrict, title text not null default '', @@ -28,7 +28,7 @@ create policy "Enable read access for all users" create table location_category ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, title text not null unique check (length(title) between 0 and 256), sort_title text unique check (length(sort_title) between 0 and 256), source text not null references data_source (id) on update cascade on delete cascade diff --git a/supabase/migrations/20240520215626_create_location_schedule.sql b/supabase/migrations/20240520215626_create_location_schedule.sql index 9229b8a..618c3a0 100644 --- a/supabase/migrations/20240520215626_create_location_schedule.sql +++ b/supabase/migrations/20240520215626_create_location_schedule.sql @@ -1,6 +1,6 @@ create table location_schedule ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, parent_schedule uuid null references location_schedule (id) on update cascade on delete cascade, location_category uuid null references location_category (id), @@ -27,7 +27,7 @@ create policy "Enable read access for all users" create table location_schedule_timetable ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id), location_schedule_id uuid not null references location_schedule (id), days text not null, diff --git a/supabase/migrations/20240520215628_create_directory_entry.sql b/supabase/migrations/20240520215628_create_directory_entry.sql index 3caeaa6..8e11cb2 100644 --- a/supabase/migrations/20240520215628_create_directory_entry.sql +++ b/supabase/migrations/20240520215628_create_directory_entry.sql @@ -1,6 +1,6 @@ create table directory_entry ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, name text not null, sort_name text not null, diff --git a/supabase/migrations/20240520215632_create_content_category.sql b/supabase/migrations/20240520215632_create_content_category.sql index 68712bd..77147be 100644 --- a/supabase/migrations/20240520215632_create_content_category.sql +++ b/supabase/migrations/20240520215632_create_content_category.sql @@ -1,6 +1,6 @@ create table content_category ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, title text not null unique check (length(title) between 0 and 256), sort_title text null unique check (length(sort_title) between 0 and 256) ); diff --git a/supabase/migrations/20240520215633_create_calendar_event.sql b/supabase/migrations/20240520215633_create_calendar_event.sql index a2162de..5bc1e86 100644 --- a/supabase/migrations/20240520215633_create_calendar_event.sql +++ b/supabase/migrations/20240520215633_create_calendar_event.sql @@ -1,6 +1,6 @@ create table calendar_event ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, recurrence_of_event_id uuid null references calendar_event (id) on update cascade on delete cascade, start_time timestamptz not null, diff --git a/supabase/migrations/20240520215636_create_feed.sql b/supabase/migrations/20240520215636_create_feed.sql index 451af39..07c4340 100644 --- a/supabase/migrations/20240520215636_create_feed.sql +++ b/supabase/migrations/20240520215636_create_feed.sql @@ -17,7 +17,7 @@ create policy "Enable read access for all users" create table feed_article ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, published_at timestamptz not null, updated_at timestamptz null, diff --git a/supabase/migrations/20240520215639_create_app_notice.sql b/supabase/migrations/20240520215639_create_app_notice.sql index 5bd136c..1358bbd 100644 --- a/supabase/migrations/20240520215639_create_app_notice.sql +++ b/supabase/migrations/20240520215639_create_app_notice.sql @@ -1,6 +1,6 @@ create table app_notice ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, created_at timestamptz not null default current_timestamp, title text not null, diff --git a/supabase/migrations/20240520215640_create_livestream.sql b/supabase/migrations/20240520215640_create_livestream.sql index 8aedd1e..895ea36 100644 --- a/supabase/migrations/20240520215640_create_livestream.sql +++ b/supabase/migrations/20240520215640_create_livestream.sql @@ -1,6 +1,6 @@ create table livestream ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, title text not null, subtitle text not null, diff --git a/supabase/migrations/20240520215641_create_bus_route.sql b/supabase/migrations/20240520215641_create_bus_route.sql index dbd32ac..09de8d0 100644 --- a/supabase/migrations/20240520215641_create_bus_route.sql +++ b/supabase/migrations/20240520215641_create_bus_route.sql @@ -1,6 +1,6 @@ create table bus_route ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, key text not null, title text not null @@ -17,7 +17,7 @@ create policy "Enable read access for all users" create table bus_route_stop ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, name text not null, coordinates jsonb not null default '[]'::jsonb @@ -34,7 +34,7 @@ create policy "Enable read access for all users" create table bus_route_timetable ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, inbound_stop uuid null references bus_route_stop (id), inbound_time time null, diff --git a/supabase/migrations/20240520215645_create_cafe.sql b/supabase/migrations/20240520215645_create_cafe.sql index 842435f..645238b 100644 --- a/supabase/migrations/20240520215645_create_cafe.sql +++ b/supabase/migrations/20240520215645_create_cafe.sql @@ -1,6 +1,6 @@ create table cafe ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, name text not null, description text, @@ -35,7 +35,7 @@ create policy "Enable read access for all users" create table cafe_item ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, title text not null, description text, @@ -87,7 +87,7 @@ create policy "Enable read access for all users" create table cafe_station_menu ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, station_title text not null, station_note text null, diff --git a/supabase/migrations/20240520215652_create_student_work.sql b/supabase/migrations/20240520215652_create_student_work.sql index c5b2db4..1403ca7 100644 --- a/supabase/migrations/20240520215652_create_student_work.sql +++ b/supabase/migrations/20240520215652_create_student_work.sql @@ -1,6 +1,6 @@ create table student_work ( - id uuid not null default uuid_generate_v4() primary key, + id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, position_title text not null, posted_at timestamptz not null, From b3babefcb8f7cb1d75d8c88cdde858920baed378 Mon Sep 17 00:00:00 2001 From: Hawken Rives Date: Tue, 21 May 2024 21:00:38 -0400 Subject: [PATCH 12/14] use geography types in location table --- .../20240520215625_create_location.sql | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/supabase/migrations/20240520215625_create_location.sql b/supabase/migrations/20240520215625_create_location.sql index aa89cc0..f2b7e4a 100644 --- a/supabase/migrations/20240520215625_create_location.sql +++ b/supabase/migrations/20240520215625_create_location.sql @@ -1,20 +1,20 @@ create table location ( - id uuid not null default gen_random_uuid() primary key, - source text not null default 'manual', - within uuid references location (id) on update cascade on delete restrict, - title text not null default '', - subtitle text not null default '', - abbreviation text not null default '', - room_number text not null default '', - outline_shape jsonb not null default '[]'::jsonb, -- geojson - coordinates jsonb not null default '[]'::jsonb, + id uuid not null default gen_random_uuid() primary key, + source text not null default 'manual', + within uuid null references location (id) on update cascade on delete restrict, + title text not null default '', + subtitle text not null default '', + abbreviation text not null default '', + room_number text not null default '', + outline_shape geography(GEOMETRYCOLLECTION) null, + coordinates geography(POINT) null, -- todo: keep these? - banner_uri text not null default '', - icon_uri text not null default '', - website_uri text not null default '', - phone text not null default '', - email text not null default '' + banner_uri text not null default '', + icon_uri text not null default '', + website_uri text not null default '', + phone text not null default '', + email text not null default '' ); alter table location From 910cc5952e54a4b0bf1a62b85f79a82d1881f697 Mon Sep 17 00:00:00 2001 From: Hawken Rives Date: Fri, 24 May 2024 09:56:50 -0400 Subject: [PATCH 13/14] poke at the readme --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 5b521eb..d72f0e7 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,12 @@ $ npm install $ npx supabase login $ npx supabase start ``` + +To set up the local database (TODO: when?) + +```sh +# to apply migrations from the local repo clone to the local database +$ npx supabase db reset +# or pull down the remote schema into the local database +$ npx supabase db pull +``` From dcddde2b90802600dbc209c2c26722244ae4bd92 Mon Sep 17 00:00:00 2001 From: Hawken Rives Date: Fri, 24 May 2024 09:57:01 -0400 Subject: [PATCH 14/14] create indexes for foreign keys --- .../migrations/20240520215621_create_link.sql | 2 ++ .../20240520215622_create_dictionary.sql | 2 ++ .../20240520215623_create_metadata.sql | 2 ++ .../20240520215625_create_location.sql | 10 +++++-- ...0240520215626_create_location_schedule.sql | 20 +++++++++----- .../20240520215628_create_directory_entry.sql | 12 +++++++++ ...20240520215632_create_content_category.sql | 2 +- .../20240520215633_create_calendar_event.sql | 10 +++++++ .../migrations/20240520215636_create_feed.sql | 8 ++++++ .../20240520215639_create_app_notice.sql | 3 +++ .../20240520215640_create_livestream.sql | 27 ++++++++++--------- .../20240520215641_create_bus_route.sql | 13 ++++++++- .../migrations/20240520215645_create_cafe.sql | 14 ++++++++++ .../20240520215652_create_student_work.sql | 3 +++ 14 files changed, 106 insertions(+), 22 deletions(-) diff --git a/supabase/migrations/20240520215621_create_link.sql b/supabase/migrations/20240520215621_create_link.sql index 077d570..3c62180 100644 --- a/supabase/migrations/20240520215621_create_link.sql +++ b/supabase/migrations/20240520215621_create_link.sql @@ -15,6 +15,8 @@ create table link primary key (type, title) ); +create index on link(source); + alter table link enable row level security; diff --git a/supabase/migrations/20240520215622_create_dictionary.sql b/supabase/migrations/20240520215622_create_dictionary.sql index 1e349ff..ebd23a7 100644 --- a/supabase/migrations/20240520215622_create_dictionary.sql +++ b/supabase/migrations/20240520215622_create_dictionary.sql @@ -13,6 +13,8 @@ create table dictionary sort_group text not null generated always as ( left(upper(sort_title), 1) ) stored ); +create index on dictionary(source); + alter table dictionary enable row level security; diff --git a/supabase/migrations/20240520215623_create_metadata.sql b/supabase/migrations/20240520215623_create_metadata.sql index 64df90b..602912f 100644 --- a/supabase/migrations/20240520215623_create_metadata.sql +++ b/supabase/migrations/20240520215623_create_metadata.sql @@ -6,6 +6,8 @@ create table metadata primary key (key, value) ); +create index on metadata(source); + alter table metadata enable row level security; diff --git a/supabase/migrations/20240520215625_create_location.sql b/supabase/migrations/20240520215625_create_location.sql index f2b7e4a..f718766 100644 --- a/supabase/migrations/20240520215625_create_location.sql +++ b/supabase/migrations/20240520215625_create_location.sql @@ -17,6 +17,9 @@ create table location email text not null default '' ); +create index on location (source); +create index on location (within); + alter table location enable row level security; @@ -30,10 +33,12 @@ create table location_category ( id uuid not null default gen_random_uuid() primary key, title text not null unique check (length(title) between 0 and 256), - sort_title text unique check (length(sort_title) between 0 and 256), + sort_title text null check (length(sort_title) between 0 and 256), source text not null references data_source (id) on update cascade on delete cascade ); +create index on location_category (source); + alter table location_category enable row level security; @@ -46,7 +51,8 @@ create policy "Enable read access for all users" create table location_category_mapping ( location_id uuid not null references location (id), - location_category_id uuid not null references location_category (id) + location_category_id uuid not null references location_category (id), + primary key (location_id, location_category_id) ); alter table location_category_mapping diff --git a/supabase/migrations/20240520215626_create_location_schedule.sql b/supabase/migrations/20240520215626_create_location_schedule.sql index 618c3a0..08b4208 100644 --- a/supabase/migrations/20240520215626_create_location_schedule.sql +++ b/supabase/migrations/20240520215626_create_location_schedule.sql @@ -16,6 +16,11 @@ create table location_schedule when location is null then location_category is not null end) ); +create index on location_schedule (source); +create index on location_schedule (location); +create index on location_schedule (location_category); +create index on location_schedule (parent_schedule); + alter table location_schedule enable row level security; @@ -27,14 +32,17 @@ create policy "Enable read access for all users" create table location_schedule_timetable ( - id uuid not null default gen_random_uuid() primary key, - source text not null references data_source (id), - location_schedule_id uuid not null references location_schedule (id), - days text not null, - open_at time not null, - open_for interval minute not null + id uuid not null default gen_random_uuid() primary key, + source text not null references data_source (id), + location_schedule uuid not null references location_schedule (id), + days text not null, + open_at time not null, + open_for interval minute not null ); +create index on location_schedule_timetable (source); +create index on location_schedule_timetable (location_schedule); + alter table location_schedule_timetable enable row level security; diff --git a/supabase/migrations/20240520215628_create_directory_entry.sql b/supabase/migrations/20240520215628_create_directory_entry.sql index 8e11cb2..260e031 100644 --- a/supabase/migrations/20240520215628_create_directory_entry.sql +++ b/supabase/migrations/20240520215628_create_directory_entry.sql @@ -17,6 +17,8 @@ create table directory_entry specialties text ); +create index on directory_entry (source); + alter table directory_entry enable row level security; @@ -32,6 +34,8 @@ create table directory_entry_category category text not null check (length(trim(category)) > 0) ); +create index on directory_entry_category (directory_entry); + alter table directory_entry_category enable row level security; @@ -54,6 +58,10 @@ create table directory_entry_location description text ); +create index on directory_entry_location (directory_entry); +create index on directory_entry_location (location); +create index on directory_entry_location (source); + alter table directory_entry_location enable row level security; @@ -77,6 +85,10 @@ create table directory_entry_organization description text ); +create index on directory_entry_organization (directory_entry); +create index on directory_entry_organization (directory_organization); +create index on directory_entry_organization (source); + alter table directory_entry_organization enable row level security; diff --git a/supabase/migrations/20240520215632_create_content_category.sql b/supabase/migrations/20240520215632_create_content_category.sql index 77147be..33b34f8 100644 --- a/supabase/migrations/20240520215632_create_content_category.sql +++ b/supabase/migrations/20240520215632_create_content_category.sql @@ -2,7 +2,7 @@ create table content_category ( id uuid not null default gen_random_uuid() primary key, title text not null unique check (length(title) between 0 and 256), - sort_title text null unique check (length(sort_title) between 0 and 256) + sort_title text null check (length(sort_title) between 0 and 256) ); alter table content_category diff --git a/supabase/migrations/20240520215633_create_calendar_event.sql b/supabase/migrations/20240520215633_create_calendar_event.sql index 5bc1e86..c41ef10 100644 --- a/supabase/migrations/20240520215633_create_calendar_event.sql +++ b/supabase/migrations/20240520215633_create_calendar_event.sql @@ -15,6 +15,11 @@ create table calendar_event constraint only_one_location check ( case when campus_location_id is not null then textual_location is null end ) ); +create index on calendar_event (source); +create index on calendar_event (recurrence_of_event_id); +create index on calendar_event (sponsoring_entity); +create index on calendar_event (campus_location_id); + alter table calendar_event enable row level security; @@ -32,6 +37,9 @@ create table calendar_event_category primary key (calendar_event_id, category_id) ); +create index on calendar_event_category (category_id); +create index on calendar_event_category (source); + alter table calendar_event_category enable row level security; @@ -52,6 +60,8 @@ create table calendar_event_link primary key (calendar_event_id, href) ); +create index on calendar_event_link (source); + alter table calendar_event_link enable row level security; diff --git a/supabase/migrations/20240520215636_create_feed.sql b/supabase/migrations/20240520215636_create_feed.sql index 07c4340..8261d65 100644 --- a/supabase/migrations/20240520215636_create_feed.sql +++ b/supabase/migrations/20240520215636_create_feed.sql @@ -6,6 +6,8 @@ create table feed primary key (uri) ); +create index on feed (source); + alter table feed enable row level security; @@ -31,6 +33,10 @@ create table feed_article constraint only_one_location check ( case when campus_location_id is not null then textual_location is null end ) ); +create index on feed_article (source); +create index on feed_article (campus_location_id); +create index on feed_article (sponsoring_entity); + alter table feed_article enable row level security; @@ -53,3 +59,5 @@ alter table feed_article_category create policy "Enable read access for all users" on feed_article_category for select to public using (true); + +create index on feed_article_category (category_id); diff --git a/supabase/migrations/20240520215639_create_app_notice.sql b/supabase/migrations/20240520215639_create_app_notice.sql index 1358bbd..5635937 100644 --- a/supabase/migrations/20240520215639_create_app_notice.sql +++ b/supabase/migrations/20240520215639_create_app_notice.sql @@ -13,6 +13,9 @@ create table app_notice platform text null ); +create index on app_notice (source); +create index on app_notice (active_until) where (active_until is not null); + alter table app_notice enable row level security; diff --git a/supabase/migrations/20240520215640_create_livestream.sql b/supabase/migrations/20240520215640_create_livestream.sql index 895ea36..a69a77b 100644 --- a/supabase/migrations/20240520215640_create_livestream.sql +++ b/supabase/migrations/20240520215640_create_livestream.sql @@ -1,19 +1,22 @@ create table livestream ( - id uuid not null default gen_random_uuid() primary key, - source text not null references data_source (id) on update cascade on delete cascade, - title text not null, - subtitle text not null, - stream_uri text not null, - tint_color text null, - text_color text null, - logo_uri text null, - calendar_source text null references data_source (id) on update cascade on delete restrict, - phone text null, - email text null, - website text null + id uuid not null default gen_random_uuid() primary key, + source text not null references data_source (id) on update cascade on delete cascade, + title text not null, + subtitle text not null, + stream_uri text not null, + tint_color text null, + text_color text null, + logo_uri text null, + calendar_event_id text null references calendar_event (id) on update cascade on delete cascade, + phone text null, + email text null, + website text null ); +create index on livestream (source); +create index on livestream (calendar_event_id); + alter table livestream enable row level security; diff --git a/supabase/migrations/20240520215641_create_bus_route.sql b/supabase/migrations/20240520215641_create_bus_route.sql index 09de8d0..817f276 100644 --- a/supabase/migrations/20240520215641_create_bus_route.sql +++ b/supabase/migrations/20240520215641_create_bus_route.sql @@ -6,6 +6,8 @@ create table bus_route title text not null ); +create index on bus_route (source); + alter table bus_route enable row level security; @@ -20,9 +22,11 @@ create table bus_route_stop id uuid not null default gen_random_uuid() primary key, source text not null references data_source (id) on update cascade on delete cascade, name text not null, - coordinates jsonb not null default '[]'::jsonb + coordinates point not null default 'POINT(0 0)'::point ); +create index on bus_route_stop (source); + alter table bus_route_stop enable row level security; @@ -44,6 +48,10 @@ create table bus_route_timetable constraint outbound_time_if_stop check (case when outbound_stop is not null then outbound_time is not null end) ); +create index on bus_route_timetable (source); +create index on bus_route_timetable (inbound_stop); +create index on bus_route_timetable (outbound_stop); + alter table bus_route_timetable enable row level security; @@ -62,6 +70,9 @@ create table bus_route_schedule active_until timestamptz null ); +create index on bus_route_schedule (timetable_id); +create index on bus_route_schedule (source); + alter table bus_route_schedule enable row level security; diff --git a/supabase/migrations/20240520215645_create_cafe.sql b/supabase/migrations/20240520215645_create_cafe.sql index 645238b..b64b58a 100644 --- a/supabase/migrations/20240520215645_create_cafe.sql +++ b/supabase/migrations/20240520215645_create_cafe.sql @@ -7,6 +7,9 @@ create table cafe location uuid null references location (id) ); +create index on cafe (source); +create index on cafe (location); + alter table cafe enable row level security; @@ -44,6 +47,8 @@ create table cafe_item nutrition jsonb not null default '{}'::jsonb -- TODO: expand this into a table ); +create index on cafe_item (source); + alter table cafe_item enable row level security; @@ -60,6 +65,8 @@ create table cafe_item_variation description text ); +create index on cafe_item_variation (cafe_item_id); + alter table cafe_item_variation enable row level security; @@ -76,6 +83,8 @@ create table cafe_item_cor primary key (cafe_item_id, cafe_cor_id) ); +create index on cafe_item_cor (cafe_cor_id); + alter table cafe_item_cor enable row level security; @@ -97,6 +106,9 @@ create table cafe_station_menu is_featured bool not null default false ); +create index on cafe_station_menu (source); +create index on cafe_station_menu (item_id); + alter table cafe_station_menu enable row level security; @@ -113,6 +125,8 @@ create table cafe_menu_schedule primary key (schedule_id, station_id) ); +create index on cafe_menu_schedule (station_id); + alter table cafe_menu_schedule enable row level security; diff --git a/supabase/migrations/20240520215652_create_student_work.sql b/supabase/migrations/20240520215652_create_student_work.sql index 1403ca7..fc68d45 100644 --- a/supabase/migrations/20240520215652_create_student_work.sql +++ b/supabase/migrations/20240520215652_create_student_work.sql @@ -19,6 +19,9 @@ create table student_work when department_name is null then department_id is not null end) ); +create index on student_work (source); +create index on student_work (department_id); + alter table student_work enable row level security;