diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ad0af01 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +# Only what the Dockerfile copies matters: keep the context small, and the secrets out +.git +target +storage +dev-db +config.yml +config.yaml +config.auth +.env +.vscode +frontend/node_modules +frontend/dist diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml new file mode 100644 index 0000000..f4a7c5c --- /dev/null +++ b/.forgejo/workflows/build.yml @@ -0,0 +1,54 @@ +# One job on purpose. The checks (eslint, vue-tsc, cargo test) live in the +# Dockerfile stages, so this workflow needs a single job image — one that has +# docker, git and node. Splitting the checks into their own jobs would mean +# `container: rust:...`, and a JavaScript action like `actions/checkout` needs +# node inside the job container, which the rust image does not have. +# +# Deliberately no third-party actions beyond `checkout`: a self-hosted Forgejo +# runner resolves `uses:` against its own mirror, and `docker/*` is usually not +# there. Plain docker commands work everywhere. +name: build + +on: + push: + branches: [main] + workflow_dispatch: + +env: + IMAGE: registry.tibiscuit.ch/studium + +jobs: + image: + runs-on: ubuntu-latest + env: + # Secrets are read into the environment here, not interpolated into the + # shell commands below: `${{ secrets.X }}` inside a `run:` ends up in the + # process arguments, and the `secrets` context is not usable in `if:`. + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + PORTAINER_WEBHOOK: ${{ secrets.PORTAINER_WEBHOOK }} + steps: + - uses: actions/checkout@v4 + + # Turns itself on as soon as the registry has authentication and the two + # secrets exist; skipped while the registry is open. + - name: Log in to the registry + if: env.REGISTRY_USERNAME != '' + run: echo "$REGISTRY_PASSWORD" | docker login registry.tibiscuit.ch -u "$REGISTRY_USERNAME" --password-stdin + + - name: Build and push + run: | + set -eu + docker build \ + --build-arg GIT_HASH="${{ github.sha }}" \ + --tag "$IMAGE:${{ github.sha }}" \ + --tag "$IMAGE:latest" \ + . + docker push "$IMAGE:${{ github.sha }}" + docker push "$IMAGE:latest" + + # Portainer re-pulls the image and recreates the stack. Enable + # "Re-pull image" on the webhook, otherwise :latest stays the old layer. + - name: Redeploy on Portainer + if: env.PORTAINER_WEBHOOK != '' + run: curl -fsS -X POST "$PORTAINER_WEBHOOK" diff --git a/.sqlx/query-022450cd184d5ccd6f09d4b80d59315f3ee9067bfc00499f192c4c217efb2d29.json b/.sqlx/query-022450cd184d5ccd6f09d4b80d59315f3ee9067bfc00499f192c4c217efb2d29.json new file mode 100644 index 0000000..daaef11 --- /dev/null +++ b/.sqlx/query-022450cd184d5ccd6f09d4b80d59315f3ee9067bfc00499f192c4c217efb2d29.json @@ -0,0 +1,52 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT s.id, s.course_id, s.tag_id, s.weekday, s.start_time, s.end_time\n FROM time_slots s JOIN courses c ON c.id = s.course_id\n WHERE c.owner = $1\n ORDER BY s.weekday, s.start_time, s.id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "course_id", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "tag_id", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "weekday", + "type_info": "Int2" + }, + { + "ordinal": 4, + "name": "start_time", + "type_info": "Time" + }, + { + "ordinal": 5, + "name": "end_time", + "type_info": "Time" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + false + ] + }, + "hash": "022450cd184d5ccd6f09d4b80d59315f3ee9067bfc00499f192c4c217efb2d29" +} diff --git a/.sqlx/query-0270806a2f7521c299bb3f33aad94d87ffa4ea83df1841912a441ae50f396d9c.json b/.sqlx/query-0270806a2f7521c299bb3f33aad94d87ffa4ea83df1841912a441ae50f396d9c.json new file mode 100644 index 0000000..59012a0 --- /dev/null +++ b/.sqlx/query-0270806a2f7521c299bb3f33aad94d87ffa4ea83df1841912a441ae50f396d9c.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM course_files\n WHERE id = $1 AND course_id IN (SELECT id FROM courses WHERE owner = $2)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [] + }, + "hash": "0270806a2f7521c299bb3f33aad94d87ffa4ea83df1841912a441ae50f396d9c" +} diff --git a/.sqlx/query-0ee076ba8e885a59e5f2b31f946401479f985c87ad4f28a2e502a05f49833889.json b/.sqlx/query-0ee076ba8e885a59e5f2b31f946401479f985c87ad4f28a2e502a05f49833889.json new file mode 100644 index 0000000..b3b3d9a --- /dev/null +++ b/.sqlx/query-0ee076ba8e885a59e5f2b31f946401479f985c87ad4f28a2e502a05f49833889.json @@ -0,0 +1,76 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT t.id, t.course_id, t.parent_id, t.name, t.description, t.links,\n t.deadline, t.done, t.time_spent,\n COALESCE(ARRAY_AGG(tt.tag_id ORDER BY tt.tag_id)\n FILTER (WHERE tt.tag_id IS NOT NULL), '{}') AS \"tag_ids!\"\n FROM tasks t\n JOIN courses c ON c.id = t.course_id AND c.owner = $1\n LEFT JOIN task_tags tt ON tt.task_id = t.id\n WHERE t.id IN (SELECT id FROM tasks WHERE parent_id IS NULL AND NOT done)\n OR t.parent_id IN (SELECT id FROM tasks WHERE parent_id IS NULL AND NOT done)\n GROUP BY t.id\n ORDER BY t.id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "course_id", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "parent_id", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "links", + "type_info": "TextArray" + }, + { + "ordinal": 6, + "name": "deadline", + "type_info": "Timestamptz" + }, + { + "ordinal": 7, + "name": "done", + "type_info": "Bool" + }, + { + "ordinal": 8, + "name": "time_spent", + "type_info": "Int4" + }, + { + "ordinal": 9, + "name": "tag_ids!", + "type_info": "Int4Array" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + true, + false, + true, + false, + true, + false, + false, + null + ] + }, + "hash": "0ee076ba8e885a59e5f2b31f946401479f985c87ad4f28a2e502a05f49833889" +} diff --git a/.sqlx/query-16a674344d0d30f8ad3b11a25481121a97e8eacd9848499c8104579505203a79.json b/.sqlx/query-16a674344d0d30f8ad3b11a25481121a97e8eacd9848499c8104579505203a79.json new file mode 100644 index 0000000..e9006f9 --- /dev/null +++ b/.sqlx/query-16a674344d0d30f8ad3b11a25481121a97e8eacd9848499c8104579505203a79.json @@ -0,0 +1,77 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT t.id, t.course_id, t.parent_id, t.name, t.description, t.links,\n t.deadline, t.done, t.time_spent,\n COALESCE(ARRAY_AGG(tt.tag_id ORDER BY tt.tag_id)\n FILTER (WHERE tt.tag_id IS NOT NULL), '{}') AS \"tag_ids!\"\n FROM tasks t\n JOIN courses c ON c.id = t.course_id AND c.owner = $2\n LEFT JOIN task_tags tt ON tt.task_id = t.id\n WHERE t.id = $1\n GROUP BY t.id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "course_id", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "parent_id", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "links", + "type_info": "TextArray" + }, + { + "ordinal": 6, + "name": "deadline", + "type_info": "Timestamptz" + }, + { + "ordinal": 7, + "name": "done", + "type_info": "Bool" + }, + { + "ordinal": 8, + "name": "time_spent", + "type_info": "Int4" + }, + { + "ordinal": 9, + "name": "tag_ids!", + "type_info": "Int4Array" + } + ], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [ + false, + false, + true, + false, + true, + false, + true, + false, + false, + null + ] + }, + "hash": "16a674344d0d30f8ad3b11a25481121a97e8eacd9848499c8104579505203a79" +} diff --git a/.sqlx/query-16d59423114e405f69eac28cbdb62197be2c57f256c331b087cac6029d285884.json b/.sqlx/query-16d59423114e405f69eac28cbdb62197be2c57f256c331b087cac6029d285884.json new file mode 100644 index 0000000..3224a94 --- /dev/null +++ b/.sqlx/query-16d59423114e405f69eac28cbdb62197be2c57f256c331b087cac6029d285884.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM courses WHERE id = $1 AND owner = $2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [] + }, + "hash": "16d59423114e405f69eac28cbdb62197be2c57f256c331b087cac6029d285884" +} diff --git a/.sqlx/query-253febb057681ba7cb7b644c5ecfa054b43e30b6f81586a98f12029d8b99c1b8.json b/.sqlx/query-253febb057681ba7cb7b644c5ecfa054b43e30b6f81586a98f12029d8b99c1b8.json new file mode 100644 index 0000000..5dac060 --- /dev/null +++ b/.sqlx/query-253febb057681ba7cb7b644c5ecfa054b43e30b6f81586a98f12029d8b99c1b8.json @@ -0,0 +1,19 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO time_slots (course_id, tag_id, weekday, start_time, end_time)\n SELECT id, $2, $3, $4, $5 FROM courses WHERE id = $1 AND owner = $6", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Int4", + "Int2", + "Time", + "Time", + "Text" + ] + }, + "nullable": [] + }, + "hash": "253febb057681ba7cb7b644c5ecfa054b43e30b6f81586a98f12029d8b99c1b8" +} diff --git a/.sqlx/query-2925a80406e08b4d5f56bb4768e5e269a6a7ff2457f50ebe83032029d7a53105.json b/.sqlx/query-2925a80406e08b4d5f56bb4768e5e269a6a7ff2457f50ebe83032029d7a53105.json new file mode 100644 index 0000000..5c82272 --- /dev/null +++ b/.sqlx/query-2925a80406e08b4d5f56bb4768e5e269a6a7ff2457f50ebe83032029d7a53105.json @@ -0,0 +1,20 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE tasks SET name = $2, description = $3, links = $4, deadline = $5, done = $6\n WHERE id = $1 AND course_id IN (SELECT id FROM courses WHERE owner = $7)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Text", + "Text", + "TextArray", + "Timestamptz", + "Bool", + "Text" + ] + }, + "nullable": [] + }, + "hash": "2925a80406e08b4d5f56bb4768e5e269a6a7ff2457f50ebe83032029d7a53105" +} diff --git a/.sqlx/query-2dbec0bbca07f88ce2ef1b67f962ce3cb5c49943895fd459c3fbef4f8255dc00.json b/.sqlx/query-2dbec0bbca07f88ce2ef1b67f962ce3cb5c49943895fd459c3fbef4f8255dc00.json new file mode 100644 index 0000000..5fe4e11 --- /dev/null +++ b/.sqlx/query-2dbec0bbca07f88ce2ef1b67f962ce3cb5c49943895fd459c3fbef4f8255dc00.json @@ -0,0 +1,65 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT id, calendar_id, title, location, description, starts_at, ends_at, all_day\n FROM events\n WHERE id = $1 AND calendar_id IN (SELECT id FROM calendars WHERE owner = $2)", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "calendar_id", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "title", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "location", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "starts_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 6, + "name": "ends_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 7, + "name": "all_day", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [ + false, + false, + false, + true, + true, + false, + true, + false + ] + }, + "hash": "2dbec0bbca07f88ce2ef1b67f962ce3cb5c49943895fd459c3fbef4f8255dc00" +} diff --git a/.sqlx/query-349db07fde24a5c20267da22f454a0ac22e1cf64de7e993a0cbc3539d979893e.json b/.sqlx/query-349db07fde24a5c20267da22f454a0ac22e1cf64de7e993a0cbc3539d979893e.json new file mode 100644 index 0000000..9245d6c --- /dev/null +++ b/.sqlx/query-349db07fde24a5c20267da22f454a0ac22e1cf64de7e993a0cbc3539d979893e.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM calendars WHERE id = $1 AND owner = $2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [] + }, + "hash": "349db07fde24a5c20267da22f454a0ac22e1cf64de7e993a0cbc3539d979893e" +} diff --git a/.sqlx/query-36c8da4b087ac7ae55b6a691867f66d94319e023a2034870cb24cf901486274a.json b/.sqlx/query-36c8da4b087ac7ae55b6a691867f66d94319e023a2034870cb24cf901486274a.json new file mode 100644 index 0000000..c732808 --- /dev/null +++ b/.sqlx/query-36c8da4b087ac7ae55b6a691867f66d94319e023a2034870cb24cf901486274a.json @@ -0,0 +1,25 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO course_files (course_id, name, kind, path)\n SELECT id, $2, 'note', $3 FROM courses WHERE id = $1 AND owner = $4\n RETURNING id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "Int4", + "Text", + "Text", + "Text" + ] + }, + "nullable": [ + false + ] + }, + "hash": "36c8da4b087ac7ae55b6a691867f66d94319e023a2034870cb24cf901486274a" +} diff --git a/.sqlx/query-384d94fe1033d6610a80da44e200119c500dfadc9a274cfd87218e2b92829383.json b/.sqlx/query-384d94fe1033d6610a80da44e200119c500dfadc9a274cfd87218e2b92829383.json new file mode 100644 index 0000000..d3bd8d9 --- /dev/null +++ b/.sqlx/query-384d94fe1033d6610a80da44e200119c500dfadc9a274cfd87218e2b92829383.json @@ -0,0 +1,19 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE grades SET name = $2, score = $3, max_score = $4, weight = $5\n WHERE id = $1 AND course_id IN (SELECT id FROM courses WHERE owner = $6)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Text", + "Float8", + "Float8", + "Float8", + "Text" + ] + }, + "nullable": [] + }, + "hash": "384d94fe1033d6610a80da44e200119c500dfadc9a274cfd87218e2b92829383" +} diff --git a/.sqlx/query-38c3a1dc809231f075a5945a79c22749b60d4401f525029edf15312f786877ce.json b/.sqlx/query-38c3a1dc809231f075a5945a79c22749b60d4401f525029edf15312f786877ce.json new file mode 100644 index 0000000..d69246a --- /dev/null +++ b/.sqlx/query-38c3a1dc809231f075a5945a79c22749b60d4401f525029edf15312f786877ce.json @@ -0,0 +1,71 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT f.id, f.course_id, f.name, f.kind, f.path, f.has_pdf, f.created_at, f.updated_at,\n COALESCE(ARRAY_AGG(ft.tag_id ORDER BY ft.tag_id)\n FILTER (WHERE ft.tag_id IS NOT NULL), '{}') AS \"tag_ids!\"\n FROM course_files f\n JOIN courses c ON c.id = f.course_id AND c.owner = $2\n LEFT JOIN file_tags ft ON ft.file_id = f.id\n WHERE f.id = $1\n GROUP BY f.id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "course_id", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "kind", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "path", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "has_pdf", + "type_info": "Bool" + }, + { + "ordinal": 6, + "name": "created_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 7, + "name": "updated_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 8, + "name": "tag_ids!", + "type_info": "Int4Array" + } + ], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + false, + false, + false, + null + ] + }, + "hash": "38c3a1dc809231f075a5945a79c22749b60d4401f525029edf15312f786877ce" +} diff --git a/.sqlx/query-3bed2d1e90bcb627f9d9d3de84cd6fdeb8dd5e96ff7a77786632e33d4015b36c.json b/.sqlx/query-3bed2d1e90bcb627f9d9d3de84cd6fdeb8dd5e96ff7a77786632e33d4015b36c.json new file mode 100644 index 0000000..bf03274 --- /dev/null +++ b/.sqlx/query-3bed2d1e90bcb627f9d9d3de84cd6fdeb8dd5e96ff7a77786632e33d4015b36c.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM time_slots\n WHERE id = $1 AND course_id = $2\n AND course_id IN (SELECT id FROM courses WHERE owner = $3)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Int4", + "Text" + ] + }, + "nullable": [] + }, + "hash": "3bed2d1e90bcb627f9d9d3de84cd6fdeb8dd5e96ff7a77786632e33d4015b36c" +} diff --git a/.sqlx/query-3dd5b4612a55c12f6518603e11c5cd1f3f5269649882f922495d355b976e532e.json b/.sqlx/query-3dd5b4612a55c12f6518603e11c5cd1f3f5269649882f922495d355b976e532e.json new file mode 100644 index 0000000..471fe4b --- /dev/null +++ b/.sqlx/query-3dd5b4612a55c12f6518603e11c5cd1f3f5269649882f922495d355b976e532e.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO calendars (owner, name, color) VALUES ($1, $2, $3)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Text", + "Text" + ] + }, + "nullable": [] + }, + "hash": "3dd5b4612a55c12f6518603e11c5cd1f3f5269649882f922495d355b976e532e" +} diff --git a/.sqlx/query-408662559ba3c8ac507033502066b1c5ebf442b7d2f1751a32240c6d3bd993e0.json b/.sqlx/query-408662559ba3c8ac507033502066b1c5ebf442b7d2f1751a32240c6d3bd993e0.json new file mode 100644 index 0000000..2e63c9f --- /dev/null +++ b/.sqlx/query-408662559ba3c8ac507033502066b1c5ebf442b7d2f1751a32240c6d3bd993e0.json @@ -0,0 +1,71 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO events\n (calendar_id, title, location, description, starts_at, ends_at, all_day)\n SELECT id, $2, $3, $4, $5, $6, $7 FROM calendars WHERE id = $1 AND owner = $8\n RETURNING id, calendar_id, title, location, description, starts_at, ends_at,\n all_day", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "calendar_id", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "title", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "location", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "starts_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 6, + "name": "ends_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 7, + "name": "all_day", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Int4", + "Text", + "Text", + "Text", + "Timestamptz", + "Timestamptz", + "Bool", + "Text" + ] + }, + "nullable": [ + false, + false, + false, + true, + true, + false, + true, + false + ] + }, + "hash": "408662559ba3c8ac507033502066b1c5ebf442b7d2f1751a32240c6d3bd993e0" +} diff --git a/.sqlx/query-45e575bf790edc0158fe5211da34f165f723e159aa829b3df2dfadb169b95c11.json b/.sqlx/query-45e575bf790edc0158fe5211da34f165f723e159aa829b3df2dfadb169b95c11.json new file mode 100644 index 0000000..ae36ef2 --- /dev/null +++ b/.sqlx/query-45e575bf790edc0158fe5211da34f165f723e159aa829b3df2dfadb169b95c11.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO task_tags (task_id, tag_id)\n SELECT $1, tag_id FROM UNNEST($2::INTEGER[]) AS tag_id\n ON CONFLICT DO NOTHING", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Int4Array" + ] + }, + "nullable": [] + }, + "hash": "45e575bf790edc0158fe5211da34f165f723e159aa829b3df2dfadb169b95c11" +} diff --git a/.sqlx/query-4b1692df89b23fb197aa0ab6b19d45bb2382d2549db1ad475400594248abbeed.json b/.sqlx/query-4b1692df89b23fb197aa0ab6b19d45bb2382d2549db1ad475400594248abbeed.json new file mode 100644 index 0000000..9c8627c --- /dev/null +++ b/.sqlx/query-4b1692df89b23fb197aa0ab6b19d45bb2382d2549db1ad475400594248abbeed.json @@ -0,0 +1,58 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT id, kind, name, code, teachers, main_page_url, folder\n FROM courses WHERE owner = $1 ORDER BY name, id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "kind", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "code", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "teachers", + "type_info": "TextArray" + }, + { + "ordinal": 5, + "name": "main_page_url", + "type_info": "Text" + }, + { + "ordinal": 6, + "name": "folder", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false, + true, + false, + true, + false + ] + }, + "hash": "4b1692df89b23fb197aa0ab6b19d45bb2382d2549db1ad475400594248abbeed" +} diff --git a/.sqlx/query-5c8607c6e765e5b87f24744438438b5fe951c58cc7be848b96cfb6a8f721585f.json b/.sqlx/query-5c8607c6e765e5b87f24744438438b5fe951c58cc7be848b96cfb6a8f721585f.json new file mode 100644 index 0000000..c868b05 --- /dev/null +++ b/.sqlx/query-5c8607c6e765e5b87f24744438438b5fe951c58cc7be848b96cfb6a8f721585f.json @@ -0,0 +1,59 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT id, kind, name, code, teachers, main_page_url, folder\n FROM courses WHERE id = $1 AND owner = $2", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "kind", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "code", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "teachers", + "type_info": "TextArray" + }, + { + "ordinal": 5, + "name": "main_page_url", + "type_info": "Text" + }, + { + "ordinal": 6, + "name": "folder", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [ + false, + false, + false, + true, + false, + true, + false + ] + }, + "hash": "5c8607c6e765e5b87f24744438438b5fe951c58cc7be848b96cfb6a8f721585f" +} diff --git a/.sqlx/query-67912ef2ee6af9f27e021328b2938d6e039dc6c4f76e878bf3b996b716c54640.json b/.sqlx/query-67912ef2ee6af9f27e021328b2938d6e039dc6c4f76e878bf3b996b716c54640.json new file mode 100644 index 0000000..0421353 --- /dev/null +++ b/.sqlx/query-67912ef2ee6af9f27e021328b2938d6e039dc6c4f76e878bf3b996b716c54640.json @@ -0,0 +1,64 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO courses (owner, kind, name, code, teachers, main_page_url, folder)\n VALUES ($7, $1, $2, $3, $4, $5, $6)\n RETURNING id, kind, name, code, teachers, main_page_url, folder", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "kind", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "code", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "teachers", + "type_info": "TextArray" + }, + { + "ordinal": 5, + "name": "main_page_url", + "type_info": "Text" + }, + { + "ordinal": 6, + "name": "folder", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text", + "Text", + "Text", + "TextArray", + "Text", + "Text", + "Text" + ] + }, + "nullable": [ + false, + false, + false, + true, + false, + true, + false + ] + }, + "hash": "67912ef2ee6af9f27e021328b2938d6e039dc6c4f76e878bf3b996b716c54640" +} diff --git a/.sqlx/query-688981658bd5bc4c5d061d0528f6c806cc2ce2fe6050dc9f52908d619285ed2e.json b/.sqlx/query-688981658bd5bc4c5d061d0528f6c806cc2ce2fe6050dc9f52908d619285ed2e.json new file mode 100644 index 0000000..4b97e4a --- /dev/null +++ b/.sqlx/query-688981658bd5bc4c5d061d0528f6c806cc2ce2fe6050dc9f52908d619285ed2e.json @@ -0,0 +1,77 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT t.id, t.course_id, t.parent_id, t.name, t.description, t.links,\n t.deadline, t.done, t.time_spent,\n COALESCE(ARRAY_AGG(tt.tag_id ORDER BY tt.tag_id)\n FILTER (WHERE tt.tag_id IS NOT NULL), '{}') AS \"tag_ids!\"\n FROM tasks t\n JOIN courses c ON c.id = t.course_id AND c.owner = $2\n LEFT JOIN task_tags tt ON tt.task_id = t.id\n WHERE t.course_id = $1\n GROUP BY t.id\n ORDER BY t.id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "course_id", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "parent_id", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "links", + "type_info": "TextArray" + }, + { + "ordinal": 6, + "name": "deadline", + "type_info": "Timestamptz" + }, + { + "ordinal": 7, + "name": "done", + "type_info": "Bool" + }, + { + "ordinal": 8, + "name": "time_spent", + "type_info": "Int4" + }, + { + "ordinal": 9, + "name": "tag_ids!", + "type_info": "Int4Array" + } + ], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [ + false, + false, + true, + false, + true, + false, + true, + false, + false, + null + ] + }, + "hash": "688981658bd5bc4c5d061d0528f6c806cc2ce2fe6050dc9f52908d619285ed2e" +} diff --git a/.sqlx/query-6a2d2f4b7c24bd671f0fe5c550e30a6297b7142cbc72ef69c073ad4072ad9ea0.json b/.sqlx/query-6a2d2f4b7c24bd671f0fe5c550e30a6297b7142cbc72ef69c073ad4072ad9ea0.json new file mode 100644 index 0000000..e9452eb --- /dev/null +++ b/.sqlx/query-6a2d2f4b7c24bd671f0fe5c550e30a6297b7142cbc72ef69c073ad4072ad9ea0.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO file_tags (file_id, tag_id)\n SELECT $1, tag_id FROM UNNEST($2::INTEGER[]) AS tag_id", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Int4Array" + ] + }, + "nullable": [] + }, + "hash": "6a2d2f4b7c24bd671f0fe5c550e30a6297b7142cbc72ef69c073ad4072ad9ea0" +} diff --git a/.sqlx/query-6f6c33a9ed3792a2dbfce200e3dd1ba4bc02fa0b93450e551584d3335475d79a.json b/.sqlx/query-6f6c33a9ed3792a2dbfce200e3dd1ba4bc02fa0b93450e551584d3335475d79a.json new file mode 100644 index 0000000..f64019d --- /dev/null +++ b/.sqlx/query-6f6c33a9ed3792a2dbfce200e3dd1ba4bc02fa0b93450e551584d3335475d79a.json @@ -0,0 +1,47 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT id, name, score, max_score, weight FROM grades\n WHERE course_id = $1 AND course_id IN (SELECT id FROM courses WHERE owner = $2)\n ORDER BY id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "score", + "type_info": "Float8" + }, + { + "ordinal": 3, + "name": "max_score", + "type_info": "Float8" + }, + { + "ordinal": 4, + "name": "weight", + "type_info": "Float8" + } + ], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [ + false, + false, + false, + false, + false + ] + }, + "hash": "6f6c33a9ed3792a2dbfce200e3dd1ba4bc02fa0b93450e551584d3335475d79a" +} diff --git a/.sqlx/query-70f85820ef9062be82f0acc0c3cc347e7e4973a4d67ef8d5f8147ffa3f5a55bc.json b/.sqlx/query-70f85820ef9062be82f0acc0c3cc347e7e4973a4d67ef8d5f8147ffa3f5a55bc.json new file mode 100644 index 0000000..a2dd5a4 --- /dev/null +++ b/.sqlx/query-70f85820ef9062be82f0acc0c3cc347e7e4973a4d67ef8d5f8147ffa3f5a55bc.json @@ -0,0 +1,19 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO grades (course_id, name, score, max_score, weight)\n SELECT id, $2, $3, $4, $5 FROM courses WHERE id = $1 AND owner = $6", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Text", + "Float8", + "Float8", + "Float8", + "Text" + ] + }, + "nullable": [] + }, + "hash": "70f85820ef9062be82f0acc0c3cc347e7e4973a4d67ef8d5f8147ffa3f5a55bc" +} diff --git a/.sqlx/query-74030bb10ad36911b9fd55d19d95f811842830075e7fbf0a7127a2a3f8e7d8c8.json b/.sqlx/query-74030bb10ad36911b9fd55d19d95f811842830075e7fbf0a7127a2a3f8e7d8c8.json new file mode 100644 index 0000000..194a73b --- /dev/null +++ b/.sqlx/query-74030bb10ad36911b9fd55d19d95f811842830075e7fbf0a7127a2a3f8e7d8c8.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM tasks\n WHERE id = $1 AND course_id IN (SELECT id FROM courses WHERE owner = $2)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [] + }, + "hash": "74030bb10ad36911b9fd55d19d95f811842830075e7fbf0a7127a2a3f8e7d8c8" +} diff --git a/.sqlx/query-78c9ebfe2e95ec579e3b2dd96e7fac23fbba3d057d006d2ab06c7f1c7f5a103b.json b/.sqlx/query-78c9ebfe2e95ec579e3b2dd96e7fac23fbba3d057d006d2ab06c7f1c7f5a103b.json new file mode 100644 index 0000000..4cfdef1 --- /dev/null +++ b/.sqlx/query-78c9ebfe2e95ec579e3b2dd96e7fac23fbba3d057d006d2ab06c7f1c7f5a103b.json @@ -0,0 +1,24 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE tasks SET time_spent = time_spent + $2\n WHERE id = $1 AND course_id IN (SELECT id FROM courses WHERE owner = $3)\n RETURNING time_spent", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "time_spent", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "Int4", + "Int4", + "Text" + ] + }, + "nullable": [ + false + ] + }, + "hash": "78c9ebfe2e95ec579e3b2dd96e7fac23fbba3d057d006d2ab06c7f1c7f5a103b" +} diff --git a/.sqlx/query-795f6a1eccdabe3c344949f9c7b382ae5709b1700f36f9d4dc3e2df5a68e882c.json b/.sqlx/query-795f6a1eccdabe3c344949f9c7b382ae5709b1700f36f9d4dc3e2df5a68e882c.json new file mode 100644 index 0000000..7b19e1d --- /dev/null +++ b/.sqlx/query-795f6a1eccdabe3c344949f9c7b382ae5709b1700f36f9d4dc3e2df5a68e882c.json @@ -0,0 +1,23 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT course_id FROM grades\n WHERE id = $1 AND course_id IN (SELECT id FROM courses WHERE owner = $2)", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "course_id", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [ + false + ] + }, + "hash": "795f6a1eccdabe3c344949f9c7b382ae5709b1700f36f9d4dc3e2df5a68e882c" +} diff --git a/.sqlx/query-7c52bfa69d62471bd84baccaf19cdb444ed02c6fea2f6b6fe00bb7e3446e1ec7.json b/.sqlx/query-7c52bfa69d62471bd84baccaf19cdb444ed02c6fea2f6b6fe00bb7e3446e1ec7.json new file mode 100644 index 0000000..c017b7a --- /dev/null +++ b/.sqlx/query-7c52bfa69d62471bd84baccaf19cdb444ed02c6fea2f6b6fe00bb7e3446e1ec7.json @@ -0,0 +1,29 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO tasks (course_id, parent_id, name, description, links, deadline, done)\n SELECT id, $2, $3, $4, $5, $6, $7 FROM courses WHERE id = $1 AND owner = $8\n RETURNING id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "Int4", + "Int4", + "Text", + "Text", + "TextArray", + "Timestamptz", + "Bool", + "Text" + ] + }, + "nullable": [ + false + ] + }, + "hash": "7c52bfa69d62471bd84baccaf19cdb444ed02c6fea2f6b6fe00bb7e3446e1ec7" +} diff --git a/.sqlx/query-920a585069249b2d0f2f0be096f231de7f96c73aa91152d11d9f6fce4f56904f.json b/.sqlx/query-920a585069249b2d0f2f0be096f231de7f96c73aa91152d11d9f6fce4f56904f.json new file mode 100644 index 0000000..3bcd37d --- /dev/null +++ b/.sqlx/query-920a585069249b2d0f2f0be096f231de7f96c73aa91152d11d9f6fce4f56904f.json @@ -0,0 +1,34 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT id, name, color FROM calendars WHERE owner = $1 ORDER BY id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "color", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false + ] + }, + "hash": "920a585069249b2d0f2f0be096f231de7f96c73aa91152d11d9f6fce4f56904f" +} diff --git a/.sqlx/query-952be5e6de4c5e1db46c523e6679f3e5405fdc6073252447a706de637f628319.json b/.sqlx/query-952be5e6de4c5e1db46c523e6679f3e5405fdc6073252447a706de637f628319.json new file mode 100644 index 0000000..7f3800c --- /dev/null +++ b/.sqlx/query-952be5e6de4c5e1db46c523e6679f3e5405fdc6073252447a706de637f628319.json @@ -0,0 +1,17 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE calendars SET name = $2, color = $3 WHERE id = $1 AND owner = $4", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Text", + "Text", + "Text" + ] + }, + "nullable": [] + }, + "hash": "952be5e6de4c5e1db46c523e6679f3e5405fdc6073252447a706de637f628319" +} diff --git a/.sqlx/query-9b165200b303773be1afd4e94cfacb4d3cff3b249e6238032a336552e94423e4.json b/.sqlx/query-9b165200b303773be1afd4e94cfacb4d3cff3b249e6238032a336552e94423e4.json new file mode 100644 index 0000000..7edc0d9 --- /dev/null +++ b/.sqlx/query-9b165200b303773be1afd4e94cfacb4d3cff3b249e6238032a336552e94423e4.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT id FROM tags WHERE slug = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false + ] + }, + "hash": "9b165200b303773be1afd4e94cfacb4d3cff3b249e6238032a336552e94423e4" +} diff --git a/.sqlx/query-9be470705776fdd73222078776b785cee496fb822c03e6a8daada1a35b1f55b8.json b/.sqlx/query-9be470705776fdd73222078776b785cee496fb822c03e6a8daada1a35b1f55b8.json new file mode 100644 index 0000000..45ec550 --- /dev/null +++ b/.sqlx/query-9be470705776fdd73222078776b785cee496fb822c03e6a8daada1a35b1f55b8.json @@ -0,0 +1,78 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT t.id, t.course_id, t.parent_id, t.name, t.description, t.links,\n t.deadline, t.done, t.time_spent,\n COALESCE(ARRAY_AGG(tt.tag_id ORDER BY tt.tag_id)\n FILTER (WHERE tt.tag_id IS NOT NULL), '{}') AS \"tag_ids!\"\n FROM tasks t\n JOIN courses c ON c.id = t.course_id AND c.owner = $3\n LEFT JOIN task_tags tt ON tt.task_id = t.id\n WHERE (t.deadline >= $1 AND t.deadline < $2)\n OR t.id IN (SELECT parent_id FROM tasks\n WHERE deadline >= $1 AND deadline < $2 AND parent_id IS NOT NULL)\n GROUP BY t.id\n ORDER BY t.id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "course_id", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "parent_id", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "links", + "type_info": "TextArray" + }, + { + "ordinal": 6, + "name": "deadline", + "type_info": "Timestamptz" + }, + { + "ordinal": 7, + "name": "done", + "type_info": "Bool" + }, + { + "ordinal": 8, + "name": "time_spent", + "type_info": "Int4" + }, + { + "ordinal": 9, + "name": "tag_ids!", + "type_info": "Int4Array" + } + ], + "parameters": { + "Left": [ + "Timestamptz", + "Timestamptz", + "Text" + ] + }, + "nullable": [ + false, + false, + true, + false, + true, + false, + true, + false, + false, + null + ] + }, + "hash": "9be470705776fdd73222078776b785cee496fb822c03e6a8daada1a35b1f55b8" +} diff --git a/.sqlx/query-9e20c5ab6d09706a9c3b600b1db6b88515a9160d0149db85df08a4f9233f5256.json b/.sqlx/query-9e20c5ab6d09706a9c3b600b1db6b88515a9160d0149db85df08a4f9233f5256.json new file mode 100644 index 0000000..4fd24b1 --- /dev/null +++ b/.sqlx/query-9e20c5ab6d09706a9c3b600b1db6b88515a9160d0149db85df08a4f9233f5256.json @@ -0,0 +1,35 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT id, name, color FROM calendars WHERE id = $1 AND owner = $2", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "color", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [ + false, + false, + false + ] + }, + "hash": "9e20c5ab6d09706a9c3b600b1db6b88515a9160d0149db85df08a4f9233f5256" +} diff --git a/.sqlx/query-a357ad6ba20b7645245646e0bbb114484a24e2bcc10ff0a291b35606c1e277f6.json b/.sqlx/query-a357ad6ba20b7645245646e0bbb114484a24e2bcc10ff0a291b35606c1e277f6.json new file mode 100644 index 0000000..f6b28df --- /dev/null +++ b/.sqlx/query-a357ad6ba20b7645245646e0bbb114484a24e2bcc10ff0a291b35606c1e277f6.json @@ -0,0 +1,66 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT id, calendar_id, title, location, description, starts_at, ends_at, all_day\n FROM events\n WHERE starts_at < $2\n AND (ends_at > $1 OR (ends_at IS NULL AND starts_at >= $1))\n AND calendar_id IN (SELECT id FROM calendars WHERE owner = $3)\n ORDER BY starts_at, id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "calendar_id", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "title", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "location", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "starts_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 6, + "name": "ends_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 7, + "name": "all_day", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Timestamptz", + "Timestamptz", + "Text" + ] + }, + "nullable": [ + false, + false, + false, + true, + true, + false, + true, + false + ] + }, + "hash": "a357ad6ba20b7645245646e0bbb114484a24e2bcc10ff0a291b35606c1e277f6" +} diff --git a/.sqlx/query-a4b97dde542b193867ca8beb78d88b75edaa08abbfe2ca09c7f3d21b03bcfcee.json b/.sqlx/query-a4b97dde542b193867ca8beb78d88b75edaa08abbfe2ca09c7f3d21b03bcfcee.json new file mode 100644 index 0000000..10bb94c --- /dev/null +++ b/.sqlx/query-a4b97dde542b193867ca8beb78d88b75edaa08abbfe2ca09c7f3d21b03bcfcee.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM grades\n WHERE id = $1 AND course_id IN (SELECT id FROM courses WHERE owner = $2)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [] + }, + "hash": "a4b97dde542b193867ca8beb78d88b75edaa08abbfe2ca09c7f3d21b03bcfcee" +} diff --git a/.sqlx/query-a71592742c8dc24bef841c890479d61aba9f6378f0006a8b22bda64e9384a369.json b/.sqlx/query-a71592742c8dc24bef841c890479d61aba9f6378f0006a8b22bda64e9384a369.json new file mode 100644 index 0000000..434103b --- /dev/null +++ b/.sqlx/query-a71592742c8dc24bef841c890479d61aba9f6378f0006a8b22bda64e9384a369.json @@ -0,0 +1,18 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE course_files SET name = $2, path = $3, has_pdf = $4, updated_at = now()\n WHERE id = $1 AND kind = 'note'\n AND course_id IN (SELECT id FROM courses WHERE owner = $5)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Text", + "Text", + "Bool", + "Text" + ] + }, + "nullable": [] + }, + "hash": "a71592742c8dc24bef841c890479d61aba9f6378f0006a8b22bda64e9384a369" +} diff --git a/.sqlx/query-ac6921146d07ec7c23da435a8c2494b15960b1fe041214b154d424f85e5b8381.json b/.sqlx/query-ac6921146d07ec7c23da435a8c2494b15960b1fe041214b154d424f85e5b8381.json new file mode 100644 index 0000000..a18e1b9 --- /dev/null +++ b/.sqlx/query-ac6921146d07ec7c23da435a8c2494b15960b1fe041214b154d424f85e5b8381.json @@ -0,0 +1,52 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT id, course_id, tag_id, weekday, start_time, end_time\n FROM time_slots WHERE course_id = $1 ORDER BY weekday, start_time, id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "course_id", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "tag_id", + "type_info": "Int4" + }, + { + "ordinal": 3, + "name": "weekday", + "type_info": "Int2" + }, + { + "ordinal": 4, + "name": "start_time", + "type_info": "Time" + }, + { + "ordinal": 5, + "name": "end_time", + "type_info": "Time" + } + ], + "parameters": { + "Left": [ + "Int4" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + false + ] + }, + "hash": "ac6921146d07ec7c23da435a8c2494b15960b1fe041214b154d424f85e5b8381" +} diff --git a/.sqlx/query-b78f7a8b18a3aa0c98841c17e496c06fb0dfde9b95082d42e5418b416d4786c8.json b/.sqlx/query-b78f7a8b18a3aa0c98841c17e496c06fb0dfde9b95082d42e5418b416d4786c8.json new file mode 100644 index 0000000..7fadf60 --- /dev/null +++ b/.sqlx/query-b78f7a8b18a3aa0c98841c17e496c06fb0dfde9b95082d42e5418b416d4786c8.json @@ -0,0 +1,72 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE events SET calendar_id = $2, title = $3, location = $4, description = $5,\n starts_at = $6, ends_at = $7, all_day = $8\n WHERE id = $1\n AND calendar_id IN (SELECT id FROM calendars WHERE owner = $9)\n AND $2 IN (SELECT id FROM calendars WHERE owner = $9)\n RETURNING id, calendar_id, title, location, description, starts_at, ends_at,\n all_day", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "calendar_id", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "title", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "location", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "starts_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 6, + "name": "ends_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 7, + "name": "all_day", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Int4", + "Int4", + "Text", + "Text", + "Text", + "Timestamptz", + "Timestamptz", + "Bool", + "Text" + ] + }, + "nullable": [ + false, + false, + false, + true, + true, + false, + true, + false + ] + }, + "hash": "b78f7a8b18a3aa0c98841c17e496c06fb0dfde9b95082d42e5418b416d4786c8" +} diff --git a/.sqlx/query-cc1eef4626da357a2605bb32c64271fffddde727a7e449dfaae658051025558a.json b/.sqlx/query-cc1eef4626da357a2605bb32c64271fffddde727a7e449dfaae658051025558a.json new file mode 100644 index 0000000..5de92b8 --- /dev/null +++ b/.sqlx/query-cc1eef4626da357a2605bb32c64271fffddde727a7e449dfaae658051025558a.json @@ -0,0 +1,46 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT id, name, color, slug, scopes FROM tags\n WHERE $1::TEXT IS NULL OR $1 = ANY(scopes)\n ORDER BY id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Jsonb" + }, + { + "ordinal": 2, + "name": "color", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "slug", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "scopes", + "type_info": "TextArray" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false, + true, + false + ] + }, + "hash": "cc1eef4626da357a2605bb32c64271fffddde727a7e449dfaae658051025558a" +} diff --git a/.sqlx/query-d037e9597a9d4ba59c0825e8f264a757319754e5882af2d6d2ef465a98590092.json b/.sqlx/query-d037e9597a9d4ba59c0825e8f264a757319754e5882af2d6d2ef465a98590092.json new file mode 100644 index 0000000..be64884 --- /dev/null +++ b/.sqlx/query-d037e9597a9d4ba59c0825e8f264a757319754e5882af2d6d2ef465a98590092.json @@ -0,0 +1,71 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT f.id, f.course_id, f.name, f.kind, f.path, f.has_pdf, f.created_at, f.updated_at,\n COALESCE(ARRAY_AGG(ft.tag_id ORDER BY ft.tag_id)\n FILTER (WHERE ft.tag_id IS NOT NULL), '{}') AS \"tag_ids!\"\n FROM course_files f\n JOIN courses c ON c.id = f.course_id AND c.owner = $2\n LEFT JOIN file_tags ft ON ft.file_id = f.id\n WHERE f.course_id = $1\n GROUP BY f.id\n ORDER BY f.created_at, f.id", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "course_id", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "kind", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "path", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "has_pdf", + "type_info": "Bool" + }, + { + "ordinal": 6, + "name": "created_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 7, + "name": "updated_at", + "type_info": "Timestamptz" + }, + { + "ordinal": 8, + "name": "tag_ids!", + "type_info": "Int4Array" + } + ], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [ + false, + false, + false, + false, + false, + false, + false, + false, + null + ] + }, + "hash": "d037e9597a9d4ba59c0825e8f264a757319754e5882af2d6d2ef465a98590092" +} diff --git a/.sqlx/query-f06ef7be08ca4b56d54b0c2e230b07d918a0f6bbbf7037c15773a0cda44f1f18.json b/.sqlx/query-f06ef7be08ca4b56d54b0c2e230b07d918a0f6bbbf7037c15773a0cda44f1f18.json new file mode 100644 index 0000000..baf83c5 --- /dev/null +++ b/.sqlx/query-f06ef7be08ca4b56d54b0c2e230b07d918a0f6bbbf7037c15773a0cda44f1f18.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM events\n WHERE id = $1 AND calendar_id IN (SELECT id FROM calendars WHERE owner = $2)", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Text" + ] + }, + "nullable": [] + }, + "hash": "f06ef7be08ca4b56d54b0c2e230b07d918a0f6bbbf7037c15773a0cda44f1f18" +} diff --git a/.sqlx/query-f6a2ae2f08904b0699b90d67b5c17b5d499cfe84d5a0dd7a58ad1411b6500182.json b/.sqlx/query-f6a2ae2f08904b0699b90d67b5c17b5d499cfe84d5a0dd7a58ad1411b6500182.json new file mode 100644 index 0000000..b9bc259 --- /dev/null +++ b/.sqlx/query-f6a2ae2f08904b0699b90d67b5c17b5d499cfe84d5a0dd7a58ad1411b6500182.json @@ -0,0 +1,14 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM task_tags WHERE task_id = $1", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4" + ] + }, + "nullable": [] + }, + "hash": "f6a2ae2f08904b0699b90d67b5c17b5d499cfe84d5a0dd7a58ad1411b6500182" +} diff --git a/.sqlx/query-f927c26731ebd4ac640777534b7072936235d40044ff86a6234046c35948823e.json b/.sqlx/query-f927c26731ebd4ac640777534b7072936235d40044ff86a6234046c35948823e.json new file mode 100644 index 0000000..8ed4199 --- /dev/null +++ b/.sqlx/query-f927c26731ebd4ac640777534b7072936235d40044ff86a6234046c35948823e.json @@ -0,0 +1,64 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE courses\n SET name = $2, code = $3, teachers = $4, main_page_url = $5, folder = $6\n WHERE id = $1 AND owner = $7\n RETURNING id, kind, name, code, teachers, main_page_url, folder", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Int4" + }, + { + "ordinal": 1, + "name": "kind", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "code", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "teachers", + "type_info": "TextArray" + }, + { + "ordinal": 5, + "name": "main_page_url", + "type_info": "Text" + }, + { + "ordinal": 6, + "name": "folder", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Int4", + "Text", + "Text", + "TextArray", + "Text", + "Text", + "Text" + ] + }, + "nullable": [ + false, + false, + false, + true, + false, + true, + false + ] + }, + "hash": "f927c26731ebd4ac640777534b7072936235d40044ff86a6234046c35948823e" +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ef395bd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,89 @@ +# Frontend: built first, it is the part that changes most often +FROM node:22-slim AS frontend +WORKDIR /build + +# Dependencies in their own layer, so a source-only change does not reinstall them +COPY frontend/package.json frontend/package-lock.json ./ +RUN npm ci + +COPY frontend/ ./ +# The checks run here rather than in a separate CI job: the build then fails on +# the runner for the same reason it would fail locally, and there is only one +# environment to keep working. +RUN npx eslint . --max-warnings=0 +RUN npm run build # type-check + vite build + + +# Backend: compiled against the sqlx offline data (`cargo sqlx prepare`), so no +# database is needed here +FROM rust:1.97-slim AS backend +WORKDIR /build + +ENV SQLX_OFFLINE=true +# Traceability: `build.rs` falls back on this when there is no git repository +ARG GIT_HASH=unknown +ENV GIT_HASH=${GIT_HASH} + +# Warm the dependency layer with a dummy main, so editing src/ does not rebuild +# every crate we depend on +COPY Cargo.toml Cargo.lock build.rs ./ +RUN mkdir src && echo 'fn main() {}' > src/main.rs \ + && cargo build --release \ + && rm -rf src + +COPY .sqlx/ .sqlx/ +COPY src/ src/ +# cargo skips a rebuild when only mtime changed: force it for our own crate +RUN touch src/main.rs \ + && cargo build --release --locked \ + && cargo test --release --locked + + +# Runtime +FROM debian:trixie-slim +LABEL org.opencontainers.image.title="studium" + +# The lecture notes are rendered by pandoc and pdflatex. latex-extra holds tcolorbox, +# sectsty and pmboxdraw, used by the template. curl serves the healthcheck, and +# fetches pandoc below. +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + curl ca-certificates \ + texlive-latex-base texlive-latex-recommended texlive-latex-extra \ + texlive-fonts-recommended texlive-pictures lmodern \ + && rm -rf /var/lib/apt/lists/* + +# The pandoc of Debian is too old for `--syntax-highlighting` (3.8+): the release of +# pandoc itself, the same version as in development +ARG PANDOC_VERSION=3.11 +RUN arch="$(dpkg --print-architecture)" \ + && curl -fsSL -o /tmp/pandoc.deb \ + "https://github.com/jgm/pandoc/releases/download/${PANDOC_VERSION}/pandoc-${PANDOC_VERSION}-1-${arch}.deb" \ + && dpkg -i /tmp/pandoc.deb \ + && rm /tmp/pandoc.deb + +# The migrations travel with the image, so the stack needs nothing from the +# repository: the `migrate` service runs this same image with another entrypoint. +COPY --from=ghcr.io/amacneil/dbmate:2 /usr/local/bin/dbmate /usr/local/bin/dbmate +COPY db/migrations/ /app/db/migrations/ + +# Not root: the app only needs to write in its storage. The folder mounted there must +# belong to this uid (`chown -R 1000:1000` on the host). +RUN useradd --uid 1000 --create-home studium \ + && mkdir -p /data/storage \ + && chown studium:studium /data/storage + +WORKDIR /app +COPY --from=backend /build/target/release/studium /usr/local/bin/studium +COPY --from=frontend /build/dist/ /app/frontend/ +COPY LaTeX_pdf/ /app/LaTeX_pdf/ +COPY docker/config.yml /etc/studium/config.yml + +USER studium +EXPOSE 3000 + +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ + CMD curl -fsS http://localhost:3000/api/version || exit 1 + +# No shell: signals reach the binary directly, so the graceful shutdown works +ENTRYPOINT ["/usr/local/bin/studium"] diff --git a/README.md b/README.md index e9e33cd..826b23e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,10 @@ shadcn-vue), on **PostgreSQL** with **dbmate** migrations. - Tailwind 4 and the shadcn-vue components already vendored in `frontend/src/components/ui` - A single binary in production: the backend serves the built frontend -There is **no authentication** in this template: add whatever the project needs. +Authentication is left to **Authelia**, in front of the app (forward auth of the reverse +proxy): it gives the login of the person in the `Remote-User` header, and each person has +their own courses, calendars and files. The app must only be reachable through Authelia. +Without it (development), `auth.default_user` in `config.yml` says who the requests act as. ## Getting started @@ -36,12 +39,29 @@ cargo run cd frontend && npm install && npm run dev ``` -Open http://localhost:5000. The api documentation is on http://localhost:3000/api/docs. +In development too, the app is reached through the real Authelia: the reverse proxy of the +server forwards `studium-dev.` to this machine (port 5000) through the VPN. Without +it, set `auth.default_user` in `config.yml` and open http://localhost:5000. +The api documentation is on http://localhost:3000/api/docs. `config.yml` is gitignored: it is where the secrets go. `config.example.yml` documents every key, keep it up to date. Every value can also come from the environment (`APP__POSTGRES__PASSWORD=...`), which is how the app is configured in production. +## Deployment + +A push on `main` builds the image (`Dockerfile`, which also runs the checks and the +tests), pushes it to `registry.tibiscuit.ch/studium` and redeploys the Portainer stack +(`.forgejo/workflows/build.yml`). The stack is `docker-compose.yml`: its header lists the +variables to set in Portainer. + +- The sql queries are checked at compile time: after changing one, run + `cargo sqlx prepare` and commit `.sqlx/`, or the image does not build. +- The files go to `/mnt/nas.data/dockers/studium` on the server, which must belong to + uid 1000 (the user of the container). +- Caddy puts Authelia in front of the app, and adds the `X-Proxy-Secret` header + (`PROXY_SECRET` of the stack): the app refuses any request without it. + ## Layout ``` @@ -54,8 +74,8 @@ key, keep it up to date. Every value can also come from the environment │ ├── services/ implementations of the repositories (postgres/sqlx) │ └── utils/ configuration ├── LaTeX_pdf/ template of the lecture notes pdf (pandoc + pdflatex) -├── storage/ files of the courses and associations, one folder each, -│ stands in for the NAS (gitignored) +├── storage/ files of the courses and associations, a folder per person +│ then per course, stands in for the NAS (gitignored) ├── db/ │ ├── migrations/ dbmate migrations │ ├── schema.sql dump regenerated by dbmate, do not edit by hand diff --git a/build.rs b/build.rs index 7db8f38..9a5332a 100644 --- a/build.rs +++ b/build.rs @@ -8,7 +8,10 @@ fn main() { .ok() .filter(|output| output.status.success()) .and_then(|output| String::from_utf8(output.stdout).ok()) - .map(|hash| hash.trim().chars().take(8).collect::()) + .map(|hash| hash.trim().to_owned()) + // No repository in a docker build: the hash is given as a build argument + .or_else(|| std::env::var("GIT_HASH").ok()) + .map(|hash| hash.chars().take(8).collect::()) .unwrap_or_else(|| "unknown".to_owned()); println!("cargo:rustc-env=GIT_HASH={git_hash}"); @@ -17,4 +20,5 @@ fn main() { env!("CARGO_PKG_NAME").replace("-", "_") ); println!("cargo:rerun-if-changed=.git/HEAD"); + println!("cargo:rerun-if-env-changed=GIT_HASH"); } diff --git a/config.auth b/config.auth new file mode 100644 index 0000000..e69de29 diff --git a/config.example.yml b/config.example.yml index 006f100..2d8e61b 100644 --- a/config.example.yml +++ b/config.example.yml @@ -15,8 +15,8 @@ postgres: frontend_dir: frontend/dist # Where the files of the courses and associations are stored (lecture notes and their -# pdf...), one folder each: Cours/CS-477 Advanced OS/Notes/..., Associations/... -# A local directory standing in for the NAS for now. +# pdf...): a folder per person, then one per course: jdoe/Cours/CS-477 Advanced OS/Notes/... +# A local directory, or the NAS mounted. storage_dir: storage # Rendering of the lecture notes to pdf (needs pandoc and pdflatex) @@ -25,15 +25,34 @@ notes: template_dir: LaTeX_pdf # Relative to template_dir logo: assets/epfl.png - # Shown in the header of the pdf, both optional - student_name: Jane Doe - student_id: "123456" -# Optional: the focus sessions of the pomodoro are also counted in TimeTagger, tagged -# with the course code, the tags and the name of the task. Without it, the time is only -# counted in the app. +# The app must be behind Authelia (forward auth of the reverse proxy), which gives the +# login of the person in the Remote-User header: each person has their own courses, +# calendars and files. The app must not be reachable without going through Authelia, +# or anyone could send this header. +auth: + # Login used for the requests without Remote-User. Only for development, never in + # production: anyone reaching the app would be this person. + # default_user: jdoe + # Where the "log out" link leads: the logout page of Authelia + # logout_url: https://auth.example.com/logout + # Secret the reverse proxy sends in the X-Proxy-Secret header: the requests without it + # are refused. Set it whenever the port of the app can be reached by anything else than + # the proxy (e.g. `openssl rand -hex 32`). + # proxy_secret: ... + +# Optional: the focus sessions of the pomodoro can also be counted in TimeTagger, tagged +# with the course code, the tags and the name of the task, for the people with a token. # timetagger: # # https://timetagger.app/api/v2 by default, or the api of your own server # url: https://timetagger.app/api/v2 -# # Api token, from the account page of TimeTagger -# token: ... + +# Settings of each person, by login, all optional +# users: +# jdoe: +# # Shown in the header of the notes (the name given by Authelia by default) +# student_name: Jane Doe +# student_id: "123456" +# # Api token, from the account page of TimeTagger. Without it, the time is only +# # counted in the app. +# timetagger_token: ... diff --git a/db/migrations/20261022100000_personal_calendars.sql b/db/migrations/20261022100000_personal_calendars.sql new file mode 100644 index 0000000..e0699ad --- /dev/null +++ b/db/migrations/20261022100000_personal_calendars.sql @@ -0,0 +1,33 @@ +-- migrate:up + +-- Personal calendars, apart from the courses and associations. Their events are not +-- tasks: nothing to check, only something happening at a time, maybe somewhere. +CREATE TABLE calendars ( + id SERIAL PRIMARY KEY, + "name" TEXT NOT NULL, + -- Hex color of the events, e.g. `#2563eb` + color TEXT NOT NULL CHECK (color ~ '^#[0-9a-fA-F]{6}$') +); + +-- An event of a personal calendar: a time range, or a single moment (a deadline, a +-- reminder) when `ends_at` is null. An all-day event goes from the midnight of its +-- first day to the midnight after its last one, in the time zone of the user. +CREATE TABLE events ( + id SERIAL PRIMARY KEY, + calendar_id INTEGER NOT NULL REFERENCES calendars (id) ON DELETE CASCADE, + title TEXT NOT NULL, + "location" TEXT, + description TEXT, + starts_at TIMESTAMPTZ NOT NULL, + ends_at TIMESTAMPTZ, + all_day BOOLEAN NOT NULL DEFAULT FALSE, + CHECK (ends_at IS NULL OR ends_at > starts_at), + CHECK (NOT all_day OR ends_at IS NOT NULL) +); + +CREATE INDEX events_starts_at_idx ON events (starts_at); +CREATE INDEX events_calendar_id_idx ON events (calendar_id); + +-- migrate:down +DROP TABLE IF EXISTS events; +DROP TABLE IF EXISTS calendars; diff --git a/db/migrations/20261024120000_users.sql b/db/migrations/20261024120000_users.sql new file mode 100644 index 0000000..dbfcee3 --- /dev/null +++ b/db/migrations/20261024120000_users.sql @@ -0,0 +1,25 @@ +-- migrate:up + +-- Each person has their own courses, associations and calendars: they are owned by the +-- login given by Authelia (`Remote-User`). Everything else (slots, grades, tasks, +-- files, events) belongs to the owner of its course or calendar. The tags stay shared. +-- What existed before is given to the first user of the app. +ALTER TABLE courses ADD COLUMN "owner" TEXT; +UPDATE courses SET "owner" = 'appellet'; +ALTER TABLE courses ALTER COLUMN "owner" SET NOT NULL; +-- The folders are in the folder of their owner in the storage: two people may have the +-- same course +ALTER TABLE courses DROP CONSTRAINT courses_folder_key; +ALTER TABLE courses ADD CONSTRAINT courses_owner_folder_key UNIQUE ("owner", folder); + +ALTER TABLE calendars ADD COLUMN "owner" TEXT; +UPDATE calendars SET "owner" = 'appellet'; +ALTER TABLE calendars ALTER COLUMN "owner" SET NOT NULL; +CREATE INDEX calendars_owner_idx ON calendars ("owner"); + +-- migrate:down +DROP INDEX IF EXISTS calendars_owner_idx; +ALTER TABLE calendars DROP COLUMN "owner"; +ALTER TABLE courses DROP CONSTRAINT courses_owner_folder_key; +ALTER TABLE courses ADD CONSTRAINT courses_folder_key UNIQUE (folder); +ALTER TABLE courses DROP COLUMN "owner"; diff --git a/db/schema.sql b/db/schema.sql index 4a2d0fa..a7d3338 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -19,6 +19,39 @@ SET default_tablespace = ''; SET default_table_access_method = heap; +-- +-- Name: calendars; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.calendars ( + id integer NOT NULL, + name text NOT NULL, + color text NOT NULL, + owner text NOT NULL, + CONSTRAINT calendars_color_check CHECK ((color ~ '^#[0-9a-fA-F]{6}$'::text)) +); + + +-- +-- Name: calendars_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.calendars_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: calendars_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.calendars_id_seq OWNED BY public.calendars.id; + + -- -- Name: course_files; Type: TABLE; Schema: public; Owner: - -- @@ -68,6 +101,7 @@ CREATE TABLE public.courses ( main_page_url text, kind text NOT NULL, folder text NOT NULL, + owner text NOT NULL, CONSTRAINT courses_kind_check CHECK ((kind = ANY (ARRAY['course'::text, 'association'::text]))) ); @@ -92,6 +126,44 @@ CREATE SEQUENCE public.courses_id_seq ALTER SEQUENCE public.courses_id_seq OWNED BY public.courses.id; +-- +-- Name: events; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.events ( + id integer NOT NULL, + calendar_id integer NOT NULL, + title text NOT NULL, + location text, + description text, + starts_at timestamp with time zone NOT NULL, + ends_at timestamp with time zone, + all_day boolean DEFAULT false NOT NULL, + CONSTRAINT events_check CHECK (((ends_at IS NULL) OR (ends_at > starts_at))), + CONSTRAINT events_check1 CHECK (((NOT all_day) OR (ends_at IS NOT NULL))) +); + + +-- +-- Name: events_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.events_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: events_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.events_id_seq OWNED BY public.events.id; + + -- -- Name: file_tags; Type: TABLE; Schema: public; Owner: - -- @@ -267,6 +339,13 @@ CREATE SEQUENCE public.time_slots_id_seq ALTER SEQUENCE public.time_slots_id_seq OWNED BY public.time_slots.id; +-- +-- Name: calendars id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.calendars ALTER COLUMN id SET DEFAULT nextval('public.calendars_id_seq'::regclass); + + -- -- Name: course_files id; Type: DEFAULT; Schema: public; Owner: - -- @@ -281,6 +360,13 @@ ALTER TABLE ONLY public.course_files ALTER COLUMN id SET DEFAULT nextval('public ALTER TABLE ONLY public.courses ALTER COLUMN id SET DEFAULT nextval('public.courses_id_seq'::regclass); +-- +-- Name: events id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.events ALTER COLUMN id SET DEFAULT nextval('public.events_id_seq'::regclass); + + -- -- Name: grades id; Type: DEFAULT; Schema: public; Owner: - -- @@ -309,6 +395,14 @@ ALTER TABLE ONLY public.tasks ALTER COLUMN id SET DEFAULT nextval('public.tasks_ ALTER TABLE ONLY public.time_slots ALTER COLUMN id SET DEFAULT nextval('public.time_slots_id_seq'::regclass); +-- +-- Name: calendars calendars_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.calendars + ADD CONSTRAINT calendars_pkey PRIMARY KEY (id); + + -- -- Name: course_files course_files_course_id_path_key; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -326,11 +420,11 @@ ALTER TABLE ONLY public.course_files -- --- Name: courses courses_folder_key; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: courses courses_owner_folder_key; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.courses - ADD CONSTRAINT courses_folder_key UNIQUE (folder); + ADD CONSTRAINT courses_owner_folder_key UNIQUE (owner, folder); -- @@ -341,6 +435,14 @@ ALTER TABLE ONLY public.courses ADD CONSTRAINT courses_pkey PRIMARY KEY (id); +-- +-- Name: events events_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.events + ADD CONSTRAINT events_pkey PRIMARY KEY (id); + + -- -- Name: file_tags file_tags_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -405,6 +507,13 @@ ALTER TABLE ONLY public.time_slots ADD CONSTRAINT time_slots_pkey PRIMARY KEY (id); +-- +-- Name: calendars_owner_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX calendars_owner_idx ON public.calendars USING btree (owner); + + -- -- Name: course_files_course_id_idx; Type: INDEX; Schema: public; Owner: - -- @@ -412,6 +521,20 @@ ALTER TABLE ONLY public.time_slots CREATE INDEX course_files_course_id_idx ON public.course_files USING btree (course_id); +-- +-- Name: events_calendar_id_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX events_calendar_id_idx ON public.events USING btree (calendar_id); + + +-- +-- Name: events_starts_at_idx; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX events_starts_at_idx ON public.events USING btree (starts_at); + + -- -- Name: grades_course_id_idx; Type: INDEX; Schema: public; Owner: - -- @@ -441,6 +564,14 @@ ALTER TABLE ONLY public.course_files ADD CONSTRAINT course_files_course_id_fkey FOREIGN KEY (course_id) REFERENCES public.courses(id) ON DELETE CASCADE; +-- +-- Name: events events_calendar_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.events + ADD CONSTRAINT events_calendar_id_fkey FOREIGN KEY (calendar_id) REFERENCES public.calendars(id) ON DELETE CASCADE; + + -- -- Name: file_tags file_tags_file_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - -- @@ -528,4 +659,6 @@ INSERT INTO public.schema_migrations (version) VALUES ('20260928120000'), ('20260928150000'), ('20260929090000'), - ('20260929180000'); + ('20260929180000'), + ('20261022100000'), + ('20261024120000'); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c879ecc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,76 @@ +# Stack for Portainer. Everything it needs lives in the image, so it can be +# deployed by pasting this file — no checkout of the repository on the server. +# +# Environment variables to set in the Portainer stack: +# IMAGE registry.tibiscuit.ch/studium:latest +# POSTGRES_PASSWORD anything, it never leaves the internal network +# PROXY_SECRET shared with Caddy (`openssl rand -hex 32`): without it in the +# X-Proxy-Secret header, a request is refused +# APP_PORT host port for the reverse proxy to point at (default 3011) +# LOGOUT_URL logout page of Authelia, e.g. https://authelia.tibiscuit.ch/logout +# +# The settings of each person also come from the environment, by login (all optional): +# APP__USERS____STUDENT_NAME, APP__USERS____STUDENT_ID, +# APP__USERS____TIMETAGGER_TOKEN + +services: + db: + image: postgres:18.3-alpine + restart: unless-stopped + environment: + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in the stack} + POSTGRES_DB: studium + volumes: + # Postgres 18 moved PGDATA to /var/lib/postgresql/18/docker and its declared + # VOLUME to /var/lib/postgresql. Mounting the pre-18 /var/lib/postgresql/data + # leaves the real data outside the volume, and trips the entrypoint. + - db_data:/var/lib/postgresql + healthcheck: + test: ['CMD-SHELL', 'pg_isready -U postgres -d studium'] + interval: 5s + timeout: 5s + retries: 10 + # initdb runs on the very first boot: do not count failures before it is done + start_period: 30s + networks: [internal] + + # Runs once per deployment, before the app: applies any new migration, then exits + migrate: + image: ${IMAGE:?set IMAGE in the stack} + restart: 'no' + entrypoint: + ['dbmate', '--migrations-dir', '/app/db/migrations', '--no-dump-schema', 'up'] + environment: + DATABASE_URL: postgres://postgres:${POSTGRES_PASSWORD}@db:5432/studium?sslmode=disable + depends_on: + db: + condition: service_healthy + networks: [internal] + + app: + image: ${IMAGE:?set IMAGE in the stack} + restart: unless-stopped + ports: + - '${APP_PORT:-3011}:3000' + environment: + APP__POSTGRES__PASSWORD: ${POSTGRES_PASSWORD} + # The app trusts the Remote-User header of Authelia: only the requests carrying + # this secret, added by Caddy, are accepted + APP__AUTH__PROXY_SECRET: ${PROXY_SECRET:?set PROXY_SECRET in the stack} + APP__AUTH__LOGOUT_URL: ${LOGOUT_URL:-} + volumes: + # Files of the courses: a folder per person. Must belong to uid 1000, the user + # of the container. + - /mnt/nas.data/dockers/studium:/data/storage + depends_on: + db: + condition: service_healthy + migrate: + condition: service_completed_successfully + networks: [internal] + +volumes: + db_data: + +networks: + internal: diff --git a/frontend/index.html b/frontend/index.html index 2b6184e..e573ec8 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -2,7 +2,10 @@ - + + + + + + + + + + + + + + + + + + diff --git a/frontend/src/components/AppSidebar.vue b/frontend/src/components/AppSidebar.vue index c766af3..c635ed4 100644 --- a/frontend/src/components/AppSidebar.vue +++ b/frontend/src/components/AppSidebar.vue @@ -1,5 +1,6 @@ + + diff --git a/frontend/src/components/calendar/EventFormDialog.vue b/frontend/src/components/calendar/EventFormDialog.vue new file mode 100644 index 0000000..0f9209f --- /dev/null +++ b/frontend/src/components/calendar/EventFormDialog.vue @@ -0,0 +1,370 @@ + + +