Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0119df3a20 | |||
| d090f650af | |||
| 490ae1898e | |||
| b46f213b2d |
+1
-1
@@ -1,3 +1,3 @@
|
||||
nodejs 20.15.1
|
||||
nodejs 22.8.0
|
||||
# python 3.12.4
|
||||
pnpm 9.7.1
|
||||
+1
-1
@@ -13,7 +13,7 @@ COPY . /app
|
||||
RUN pnpm run build
|
||||
|
||||
|
||||
FROM base
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=prod /app/node_modules /app/node_modules
|
||||
COPY --from=prod /app/dist /app
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
REGISTRY=registry.sakal.us
|
||||
IMAGE_NAME=blog-astro
|
||||
|
||||
# get version from package.json and remove quotes:
|
||||
VERSION=$(pnpm pkg get version | xargs)
|
||||
|
||||
|
||||
docker build -t "${REGISTRY}/${IMAGE_NAME}:v${VERSION}" --target final .
|
||||
docker push "${REGISTRY}/${IMAGE_NAME}:v${VERSION}"
|
||||
@@ -0,0 +1,32 @@
|
||||
---
|
||||
title: MySQL JSON Shenanigans
|
||||
date: 2024-11-19
|
||||
---
|
||||
|
||||
In an effort to support out-of-date installations of our app, I had to keep a JSON column in our database. The column is obsolete, as are the values within it; but these installations continue to use it. So, knowing this, I decided to put the proper values into the column. I didn't want to pollute the code of our services to do so, though. So I made it into a `GENERATED` column.
|
||||
|
||||
I ran into two issues.
|
||||
|
||||
First, MySQL doesn't have a way to omit `NULL` values from a JSON array.
|
||||
|
||||
Second, the strings in the resulting array had `\u0000` interspersed between each character. This is due to how MySQL represents strings in a regular column versus how they are represented in a JSON column. I'd have to look it up, but I think I recall that by default MySQL varchars are 16-bits per character, and JSON strings are UTF-8.
|
||||
|
||||
I "solved" the first issue by using `IF()` statements to represent all possible combinations of values. Luckily there were only 4. The only other solution I saw involved `TRIGGER`s. No, thank you.
|
||||
|
||||
The second issue was solved by using `JSON_QUOTE()` followed by `JSON_UNQUOTE()` to remove the `\u0000` characters.
|
||||
|
||||
```sql
|
||||
ALTER TABLE lectures
|
||||
MODIFY COLUMN vimeo_video_links JSON GENERATED ALWAYS AS (
|
||||
IF(m3u8_url IS NOT NULL AND mp4_url IS NOT NULL,
|
||||
JSON_ARRAY(JSON_UNQUOTE(JSON_QUOTE(m3u8_url)), JSON_UNQUOTE(JSON_QUOTE(mp4_url))),
|
||||
IF(m3u8_url IS NOT NULL AND mp4_url IS NULL,
|
||||
JSON_ARRAY(JSON_UNQUOTE(JSON_QUOTE(m3u8_url))),
|
||||
IF(m3u8_url IS NULL AND mp4_url IS NOT NULL,
|
||||
JSON_ARRAY(JSON_UNQUOTE(JSON_QUOTE(mp4_url))),
|
||||
NULL
|
||||
)
|
||||
)
|
||||
)
|
||||
) STORED;
|
||||
```
|
||||
@@ -1,17 +1,12 @@
|
||||
---
|
||||
import Layout from "../layouts/Layout.astro";
|
||||
|
||||
export const prerender = false;
|
||||
---
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>Current Time</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Current Time</h1>
|
||||
<p>This page is rendered on the server.</p>
|
||||
<time datetime={new Date().toISOString()}>
|
||||
{new Date().toLocaleString()}
|
||||
</time>
|
||||
</body>
|
||||
</html>
|
||||
<Layout title="Current Time">
|
||||
<h1>Current Time</h1>
|
||||
<p>This page is rendered on the server.</p>
|
||||
<time datetime={new Date().toISOString()}>
|
||||
{new Date().toLocaleString()}
|
||||
</time>
|
||||
</Layout>
|
||||
@@ -1,16 +1,10 @@
|
||||
---
|
||||
import Layout from '../layouts/Layout.astro';
|
||||
---
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>Current Time</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Current Time</h1>
|
||||
<p>This page is rendered on the server.</p>
|
||||
<time datetime={new Date().toISOString()}>
|
||||
{new Date().toLocaleString()}
|
||||
</time>
|
||||
</body>
|
||||
</html>
|
||||
<Layout title='Prerendered Time'>
|
||||
<h1>Current Time</h1>
|
||||
<p>This page is rendered on the server.</p>
|
||||
<time datetime={new Date().toISOString()}>
|
||||
{new Date().toLocaleString()}
|
||||
</time>
|
||||
</Layout>
|
||||
Reference in New Issue
Block a user