Skip to content
Snippets Groups Projects
Commit abb0f8f0 authored by Linus Keiser's avatar Linus Keiser :speech_balloon:
Browse files

build: apply db schema on startup, work on containerization (wip)

parent 37bfe8b1
No related branches found
No related tags found
No related merge requests found
Pipeline #571213 passed
Showing
with 14126 additions and 25531 deletions
......@@ -31,14 +31,6 @@ Thumbs.db
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
# Devenv
.devenv
.devenv*
devenv.local.nix
# direnv
.direnv
# pre-commit
.pre-commit-config.yaml
......@@ -46,4 +38,4 @@ devenv.local.nix
.vscode/
# dev DB
/data
/run
stages:
- build
- test
variables:
CACHIX_CACHE_NAME: grady
.linux-configuration: &linux-configuration
image: docker.nix-community.org/nixpkgs/cachix-flakes
before_script:
- cachix use "$CACHIX_CACHE_NAME"
- echo '{ cachix.push = "'"$CACHIX_CACHE_NAME"'"; }' > devenv.local.nix
- cat devenv.local.nix
- nix profile install nixpkgs#devenv
build:linux:
<<: *linux-configuration
stage: build
script:
- CACHIX_AUTH_TOKEN=$CACHIX_AUTH_TOKEN devenv shell
# - devenv tasks run grady:build
# artifacts:
# paths:
# - build/
tests:linux:
<<: *linux-configuration
stage: test
script:
- echo noop
# - devenv test
# - devenv shell hello
# - devenv shell bash -c "hello && say-bye"
/nix/store/bw5hbj2l431hn0sxgpc9f332sxr3zx2r-pre-commit-config.json
\ No newline at end of file
/nix/store/0r0k7dg4b4wk291f56wzc824nhdmlgh5-pre-commit-config.json
\ No newline at end of file
......@@ -19,47 +19,70 @@ If you are using [Nix](https://nixos.org/), all you'll need is:
Otherwise, you'll need the following to start developing:
- [Docker](https://docker.com)
- Node/`npm`
- Deno
- [Bun](https://bun.sh/docs/installation)
### Installing
<!-- ### Installing -->
See https://devenv.sh/getting-started/ for help with installing Nix and devenv on your system.
<!-- See https://devenv.sh/getting-started/ for help with installing Nix and devenv on your system. -->
### Running
### Running the Application
With `devenv`:
There are two ways to run the application for local development: **with only `devenv`** or **with Docker**. Choose the method that best suits your needs.
---
#### Option 1: Running with `devenv` (Recommended for Local Development)
After entering the `devenv` shell, use it to set up and run the application and all required services locally.
> If you're running devenv without direnv for automatic shell activation, enter the shell via `devenv shell` first
```sh
devenv up
```
> TODO: document database migrations
<!-- > **Note:** Documentation for database migrations is still in progress (TODO). -->
Without `devenv`:
---
Start local SurrealDB instance with development credentials
#### Option 2: Running without `devenv`
If you prefer not to use `devenv`, you can start a local SurrealDB instance manually using Docker.
1. Create a directory to persist the development database (this is needed to ensure correct filesystem permissions):
```sh
mkdir -p run/data
```
2. Run the SurrealDB Docker container with development credentials:
```sh
mkdir -p data/surreal
docker run --rm --pull always \
-e SURREAL_EXPERIMENTAL_GRAPHQL=true \
-p 8000:8000 \
--user $(id -u) \
-v $(pwd)/data/surreal:/data \
-v $(pwd)/run/data:/data \
-v $(pwd)/db:/db \
surrealdb/surrealdb:latest start \
--user root\
--pass root\
--log debug \
rocksdb:/data/data/surreal
--bind 127.0.0.1:8000 \
--user root \
--pass root \
--log debug \
--import-file /db/schema/schema.surql \
rocksdb://data/dev.db
```
Start the application (install dependencies if needed)
3. Install dependencies
```sh
bun install
````
4. Initialize development data
```sh
npm install
npm run dev -- --open
bun --bun run db/manage.ts init
```
5. Start the app
```sh
bun --bun run dev
```
---
## License
......
bun.lock 0 → 100644
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
const data = Bun.file("./tmp.json");
const parsed = JSON.parse(await data.text());
console.log(parsed);
{
"meta": {
"version": "6.1.0"
},
"data": {
"module": {
"module_reference": "B.Inf.1102",
"total_score": 32,
"pass_score": 32,
"pass_only": false
},
"submission_types": [
{
"name": "[a04-2] Formale Sprachen, Grammatik I",
"full_score": 4,
"description": "<?xml version='1.0'?><div><p>Formulieren Sie das Pumping-Lemma für <strong>reguläre</strong> Sprachen.</p>\r\n<p>Verwenden Sie einfachen Text und benutzen Sie <strong>AsciiMath</strong> für zusätzliche Schriftzeichen und Symbole. Sie können, z.B. zur Gliederung des Text, zusätzlich die Auszeichnungssprache <strong>Markdown</strong> verwenden.</p></div>",
"solution": "# [a04-2] Formale Sprachen, Grammatik I (4 Punkte)\n\n[//]: # Es kommt nicht auf die AsciiMath/Markdown-Syntax an\n\n[//]: # Wichtig ist, dass man erkenne kann, was gemeint ist\n\n#### Pumping Lemma\n\n[//]: # 0.5 Punkte\nSei $L$ eine reguläre Sprache.\n\n[//]: # 0.5 Punkte\nDann gibt es einen Konstante $k in NN$,\n\n[//]: # 1 Punkt\nsodass es für jedes Wort $w in L$ mit $|w| >= k$ eine Zerlegung \n$x, y, z in Sigma^**$ gibt, d.h. $w = xyz$,\n\n[//]: # 1 Punkt\nfür die Folgendes gilt.\n\n- $|xy| <= k$\n- $|y| >= 1$\n\n[//]: # 1 Punkt\n- $xy in L$\n- für alle $i in NN$ gilt $xy^iz in L$\n",
"programming_language": "markdown"
},
{
"name": "[a04-3] Formale Sprachen, Grammatik II",
"full_score": 8,
"description": "<?xml version='1.0'?><div><p>Zeigen Sie, dass die Sprache</p>\r\n<p><span class='latex'>\\(L = \\{\\ a^m b^m c^m\\ | \\mbox{ mit } m \\in \\mathbb{N}\\ \\}\\)</span> über dem Alphabet <span class='latex'>\\(\\Sigma = \\{a, b, c\\}\\)</span></p>\r\n<p>nicht <strong>regulär</strong> ist.</p>\r\n<p>Verwenden Sie einfachen Text und benutzen Sie <strong>AsciiMath</strong> für zusätzliche Schriftzeichen und Symbole. Sie können, z.B. zur Gliederung des Text, zusätzlich die Auszeichnungssprache <strong>Markdown</strong> verwenden.</p></div>",
"solution": "# [a04-3] Formale Sprachen, Grammatik II (8 Punkte)\n\n[//]: # Es kommt nicht auf die AsciiMath/Markdown-Syntax an]\n\n[//]: # Wichtig ist, dass man erkenne kann, was gemeint ist\n\n[//]: # Beweis muss nicht identisch sein, Ansatz und Umsetzung müssen stimmen\n\n### Pumping Lemma II\n\n#### Behauptung\n\n$L = {a^m b^m c^m | $ mit $ m in NN}$ über dem Alphabet\n$\\Sigma = {a,b,c}$ ist keine reguläre Sprache.\n\n#### Beweis\n\n##### Annahme\n\n[//]: # 1 Punkt\n$L$ ist regulär\n\n##### Folgerung\n\n[//]: # 1 Punkt\nEs gilt das Pumping Lemma für reguläre Sprachen mit Konstante $p in NN$.\n\n##### Auswahl\n\n[//]: # 1 Punkt\nWähle $w = a^p b^p c^p$, dann gilt $|w| = 3p >= p$.\n\n[//]: # 1 Punkt\nSei $x, y, z in \\Sigma^**$ eine beliebige Zerlegung von $w$, d.h. $w = xyz$, für die Folgendes gilt.\n\n- $|xy| <= p$\n- $|y| >= 1$\n\n[//]: # 2 Punkte\nD.h. mit $|xy| <= p$ und $|y| >= 1$ gilt $xy = a^{i+j}$\nmit $i+j <= p$ und $j > 0$.\n\n##### Abpumpen\n\n[//]: # 1 Punkt\nEs gilt $xz = a^{m-j} b^m c^m notin L$, weil $j > 0$.\n\n##### Widerspruch\n\n[//]: # 1 Punkt\nFür jede Zerlegung $w = xyz$ mit $|xy| <= p$ und $|y| >= 1$\ngilt $xz notin L$, dass ist ein Widerspruch zur Annahme.\n\n##### Aufpumpen (alternativ)\n\n[//]: # 1 Punkt\nEs gilt $xy^kz = a^{m+kj} b^m c^m notin L$, weil $j > 0$.\n\n##### Widerspruch\n\n[//]: # 1 Punkt\nFür jede Zerlegung $w = xyz$ mit $|xy| <= p$ und $|y| >= 1$\ngilt $xy^kz notin L$ für $k in NN$, dass ist ein Widerspruch zur Annahme.\n\n#### Ergebnis\n$L$ ist keine reguläre Sprache.\n\n",
"programming_language": "markdown"
},
{
"name": "[a07-2] Haskell - Typklassen",
"full_score": 8,
"description": "<?xml version='1.0'?><div><p>Betrachten Sie den Anfang der Typklasse <code>Compare</code> in Haskell.</p>\r\n<pre>class (Eq a) =&gt; Compare a where<br/> (&lt;|), (&lt;=|), (|&gt;=), (|&gt;) :: a -&gt; a -&gt; Bool<br/> min :: a -&gt; a -&gt; a\r\n</pre>\r\n<p>Vervollständigen Sie die Typklasse <code>Compare</code>, sodass zur Bildung einer Instanz der Typklasse nur einer der vier deklarierten Operatoren definiert werden muss.</p>\r\n<p><span style='text-decoration: underline;'>Hinweis.</span> Vergessen Sie die Funktion <code>min</code> nicht.</p></div>",
"solution": "-- [a07-2] Haskell - Typklassen (8 Punkte)\n\n-- die Operatoren und Funktionen sollten richtig definiert sein\n-- die vier Operatoren muessen 'im Kreis' von einander abhaengen\n\n-- Vorgabe\nclass (Eq a) => Compare a where\n (<|), (<=|), (|>=), (|>) :: a -> a -> Bool\n min :: a -> a -> a\n\n-- Operatoren\n-- jeweils 1.5 Punkte (6 Punkte)\n x <=| y = x <| y || x == y\n x <| y = not (x |>= y)\n x |>= y = x |> y || x == y\n x |> y = not (x <=| y)\n \n-- alternativ\n-- x <| y = (x <=| y) && not (x == y)\n-- x <=| y = not(x |> y)\n-- x |> y = (x |>= y) && not (x == y)\n-- x |>= y = not(x <| y)\n\n-- alternativ mit Funktionen\n-- (<=|) x y = (<|) x y || (==) x y\n-- (<|) x y = not $ (|>=) x y)\n-- (|>=) x y = (|>) x y || (==) x y\n-- (|>) x y = not $ (<=|) x y\n\n-- falsch, zwei Kreise\n-- trotzdem jeweils 1 Punkt pro Operator\n-- x <=| y = x <| y || x == y\n-- x <| y = (x <=| y) && (not (x == y))\n-- x |>= y = x |> y || x == y\n-- x |> y = (x|>= y) && (not (x == y))\n\n-- Minimum (eine Moeglichkeit)\n-- 2 Punkte\n min x y\n | x <| y = x\n | otherwise = y\n",
"programming_language": "haskell"
}
],
"students": [
{
"fullname": "Strenuous Subject",
"identifier": "strenuous-subject",
"username": "strenuous-subject",
"email": "",
"exercise_groups": [],
"submissions": [
{
"code": "Sei $L$ eine regulaere Sprache. Dann existiert eine natuerliche Zahl $k in NN$ (die Pumping-Konstante), sodass fuer alle Worte $w in L$ mit $|w| ge k$ die folgenden Bedingungen erfuellt sind:\n\n- es gilt $w = xyz$ mit $x,y,z in L$,\n- es gilt $|y|>0$ bzw. $y ne epsilon$,\n- es gilt $|xy| le k$,\n- fuer alle natuerlichen Zahlen $i in NN_{0}$ gilt $xy^{i}z in L$.",
"source_code": null,
"type": "[a04-2] Formale Sprachen, Grammatik I",
"tests": [
{
"name": "EmptyTest",
"annotation": "",
"label": "NOT_EMPTY"
}
]
},
{
"code": "### Überführungsfunktion\n\n| $p in Q$ | $delta_p(a)$ | $delta_p(b)$ |\n| :--- | :--- | :--- |\n| ${q_0}$ | ${q_0, q_1}$ | ${q_1}$ |\n| ${q_1}$ | $O/$ | ${q_2}$ |\n| ${q_2}$ | $O/$ | ${q_1, q_3}$ |\n| ${q_0, q_1}$ | ${q_0, q_1}$ | ${q_1, q_2}$ |\n| ${q_1, q_2}$ | $O/$ |${q_1,q_2,q_3}$|\n| ${q_1, q_3}$ | ${q_0}$ | ${q_2}$ |\n| ${q_1, q_2, q_3}$ | ${q_0}$ |${q_1,q_2,q_3}$|\n| $O/$ | $O/$ | $O/$ |\n\n\n### Akzeptierende Zustände\n\nF = {q_1}",
"source_code": null,
"type": "[a04-1] Formale Sprachen, Automat",
"tests": [
{
"name": "EmptyTest",
"annotation": "",
"label": "NOT_EMPTY"
}
]
},
{
"code": "(|>=) a b = not ((<|) a b)\n(<=|) a b = not ((|>) a b)\n(<|) a b = (<=|) a b && a /= b\n\nmin a b = if (<|) a b then a else b",
"source_code": null,
"type": "[a07-2] Haskell - Typklassen",
"tests": [
{
"name": "EmptyTest",
"annotation": "",
"label": "NOT_EMPTY"
}
]
},
{
"code": "Angenommen, $L$ ist regulaer. Sei $k$ nun die Pumping-Konstante.\n\nSetze $w=a^{m}b^{m}c^{m}=xyz$ mit $3m be k$. Setze weiterhin $xy = a^{m}b^{m}$ und $y=b^{m}$.\n\nDann ist $|xy|=2m<k$ und $|y|=m>0$.\n\nPumpe $y$ nun auf: Dann ist $w'=xy^{2}z=a^{m}b^{2m}c^{m}$. Diese Zahl ist aber nicht in $L$, da die Summe aller Zeichen nicht $3m$ sondern $4m$ betraegt.\n\nDas ist aber ein Widerspruch zur Annahme, dass $L$ regulaer ist. Somit ist die Annahme falsch und $L$ nicht regulaer.",
"source_code": null,
"type": "[a04-3] Formale Sprachen, Grammatik II",
"tests": [
{
"name": "EmptyTest",
"annotation": "",
"label": "NOT_EMPTY"
}
]
}
]
}
]
}
}
-- ------------------------------
-- PARAMS
-- ------------------------------
DEFINE PARAM $latest_user VALUE (SELECT username, slug, created_at FROM user ORDER BY created_at DESC LIMIT 1);
DEFINE PARAM $total_posts VALUE count((SELECT id FROM post));
DEFINE PARAM $total_users VALUE count((SELECT id FROM user));
DEFINE PARAM $your_posts VALUE count((SELECT id FROM post WHERE author = $author));
-- ------------------------------
-- SCOPES
-- ------------------------------
DEFINE SCOPE user SESSION 1h SIGNUP (CREATE user CONTENT { created_at: time::now(), password: crypto::argon2::generate($password), username: $username }) SIGNIN (SELECT * OMIT password FROM user WHERE (username = $username AND crypto::argon2::compare(password, $password)));
-- ------------------------------
-- TABLE: post
-- ------------------------------
DEFINE TABLE post SCHEMAFULL;
DEFINE FIELD author ON post TYPE record<user>;
DEFINE FIELD content ON post TYPE string;
DEFINE FIELD created_at ON post TYPE datetime DEFAULT time::now();
DEFINE FIELD slug ON post FLEXIBLE TYPE string DEFAULT string::slug(title);
DEFINE FIELD title ON post TYPE string;
DEFINE FIELD updated_at ON post TYPE option<datetime> VALUE time::now();
DEFINE INDEX author ON post FIELDS author;
DEFINE INDEX slug ON post FIELDS slug UNIQUE;
DEFINE INDEX title ON post FIELDS title UNIQUE;
-- ------------------------------
-- TABLE: user
-- ------------------------------
DEFINE TABLE user SCHEMAFULL;
DEFINE FIELD created_at ON user TYPE datetime DEFAULT time::now();
DEFINE FIELD etoro ON user TYPE option<string> ASSERT $value = NONE OR string::is::url($value);
DEFINE FIELD github ON user TYPE option<string> ASSERT $value = NONE OR string::is::url($value);
DEFINE FIELD linkedin ON user TYPE option<string> ASSERT $value = NONE OR string::is::url($value);
DEFINE FIELD password ON user TYPE string PERMISSIONS FOR select, create, update, delete WHERE id = $auth.id;
DEFINE FIELD slug ON user TYPE string DEFAULT string::slug(username);
DEFINE FIELD updated_at ON user TYPE option<datetime> VALUE time::now();
DEFINE FIELD username ON user TYPE string;
DEFINE FIELD website ON user TYPE option<string> ASSERT $value = NONE OR string::is::url($value);
DEFINE INDEX slug ON user FIELDS slug UNIQUE;
DEFINE INDEX username ON user FIELDS username UNIQUE;
-- ------------------------------
-- TABLE: username_lookup
-- ------------------------------
DEFINE TABLE username_lookup SCHEMALESS AS SELECT username FROM user PERMISSIONS FOR select FULL, FOR create, update, delete NONE;
DEFINE INDEX username_lookup ON username_lookup FIELDS username;
-- ------------------------------
-- TABLE: your_posts
-- ------------------------------
DEFINE TABLE your_posts SCHEMALESS AS SELECT *, author[*] FROM post PERMISSIONS FOR select WHERE author = $auth.id, FOR create, update, delete NONE;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment