Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Check source file limits
run: npm run check:file-limits

- name: Run tests
run: npm test -- --run

Expand Down
20 changes: 16 additions & 4 deletions backend/src/bin/export_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ async fn main() -> Result<()> {
.collect::<Result<Vec<_>>>()?;

let page_rows = sqlx::query_as::<_, SitePageRow>(
"SELECT id, slug, title, description, nav_label, show_in_nav, order_index, is_published, hero_json, layout_json, created_at, updated_at FROM site_pages ORDER BY order_index, title",
r#"SELECT id, slug, title, description, nav_label, show_in_nav, order_index,
is_published, hero_json, layout_json, created_at, updated_at
FROM site_pages
ORDER BY order_index, title"#,
)
.fetch_all(&pool)
.await
Expand Down Expand Up @@ -239,7 +242,10 @@ async fn main() -> Result<()> {
.collect::<Result<Vec<_>>>()?;

let post_rows = sqlx::query_as::<_, SitePostRow>(
"SELECT id, page_id, title, slug, excerpt, content_markdown, is_published, published_at, order_index, created_at, updated_at FROM site_posts ORDER BY page_id, order_index, created_at",
r#"SELECT id, page_id, title, slug, excerpt, content_markdown, is_published,
published_at, order_index, created_at, updated_at
FROM site_posts
ORDER BY page_id, order_index, created_at"#,
)
.fetch_all(&pool)
.await
Expand All @@ -263,7 +269,10 @@ async fn main() -> Result<()> {
.collect::<Vec<_>>();

let tutorial_rows = sqlx::query_as::<_, TutorialRow>(
"SELECT id, title, description, icon, color, topics, content, version, created_at, updated_at FROM tutorials ORDER BY created_at",
r#"SELECT id, title, description, icon, color, topics, content, version,
created_at, updated_at
FROM tutorials
ORDER BY created_at"#,
)
.fetch_all(&pool)
.await
Expand Down Expand Up @@ -328,7 +337,10 @@ async fn main() -> Result<()> {
.with_context(|| format!("Failed to write export file at {}", path.display()))?;

println!(
"Export completed:\n site_content: {}\n pages: {}\n posts: {}\n tutorials: {}\n tutorial_topics: {}\n saved to {}",
concat!(
"Export completed:\n site_content: {}\n pages: {}\n posts: {}\n",
" tutorials: {}\n tutorial_topics: {}\n saved to {}",
),
bundle.site_content.len(),
bundle.pages.len(),
bundle.posts.len(),
Expand Down
38 changes: 28 additions & 10 deletions backend/src/bin/import_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,11 @@ async fn import_site_content(
.context("Failed to serialize site_content entry")?;

sqlx::query(
"INSERT INTO site_content (section, content_json, updated_at) VALUES (?, ?, COALESCE(?, CURRENT_TIMESTAMP)) \
ON CONFLICT(section) DO UPDATE SET content_json = excluded.content_json, updated_at = COALESCE(excluded.updated_at, CURRENT_TIMESTAMP)",
r#"INSERT INTO site_content (section, content_json, updated_at)
VALUES (?, ?, COALESCE(?, CURRENT_TIMESTAMP))
ON CONFLICT(section) DO UPDATE SET
content_json = excluded.content_json,
updated_at = COALESCE(excluded.updated_at, CURRENT_TIMESTAMP)"#,
)
.bind(&item.section)
.bind(&serialized)
Expand All @@ -200,16 +203,24 @@ async fn import_site_pages(
serde_json::to_string(&item.layout).context("Failed to serialize page layout JSON")?;

sqlx::query(
"INSERT INTO site_pages (id, slug, title, description, nav_label, show_in_nav, order_index, is_published, hero_json, layout_json, created_at, updated_at) \
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, COALESCE(?, CURRENT_TIMESTAMP), COALESCE(?, CURRENT_TIMESTAMP)) \
ON CONFLICT(id) DO UPDATE SET slug = excluded.slug, title = excluded.title, description = excluded.description, nav_label = excluded.nav_label, show_in_nav = excluded.show_in_nav, order_index = excluded.order_index, is_published = excluded.is_published, hero_json = excluded.hero_json, layout_json = excluded.layout_json, updated_at = COALESCE(excluded.updated_at, CURRENT_TIMESTAMP)",
r#"INSERT INTO site_pages (
id, slug, title, description, nav_label, show_in_nav, order_index,
is_published, hero_json, layout_json, created_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
COALESCE(?, CURRENT_TIMESTAMP), COALESCE(?, CURRENT_TIMESTAMP))
ON CONFLICT(id) DO UPDATE SET
slug = excluded.slug, title = excluded.title,
description = excluded.description, nav_label = excluded.nav_label,
show_in_nav = excluded.show_in_nav, order_index = excluded.order_index,
is_published = excluded.is_published, hero_json = excluded.hero_json,
layout_json = excluded.layout_json,
updated_at = COALESCE(excluded.updated_at, CURRENT_TIMESTAMP)"#,
)
.bind(&item.id)
.bind(&item.slug)
.bind(&item.title)
.bind(&item.description)
.bind(&item.nav_label)

.bind(if item.show_in_nav { 1 } else { 0 })
.bind(item.order_index)
.bind(if item.is_published { 1 } else { 0 })
Expand All @@ -231,17 +242,24 @@ async fn import_site_posts(
) -> Result<()> {
for item in items {
sqlx::query(
"INSERT INTO site_posts (id, page_id, title, slug, excerpt, content_markdown, is_published, published_at, order_index, created_at, updated_at) \
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, COALESCE(?, CURRENT_TIMESTAMP), COALESCE(?, CURRENT_TIMESTAMP)) \
ON CONFLICT(id) DO UPDATE SET page_id = excluded.page_id, title = excluded.title, slug = excluded.slug, excerpt = excluded.excerpt, content_markdown = excluded.content_markdown, is_published = excluded.is_published, published_at = excluded.published_at, order_index = excluded.order_index, updated_at = COALESCE(excluded.updated_at, CURRENT_TIMESTAMP)",
r#"INSERT INTO site_posts (
id, page_id, title, slug, excerpt, content_markdown, is_published,
published_at, order_index, created_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,
COALESCE(?, CURRENT_TIMESTAMP), COALESCE(?, CURRENT_TIMESTAMP))
ON CONFLICT(id) DO UPDATE SET
page_id = excluded.page_id, title = excluded.title, slug = excluded.slug,
excerpt = excluded.excerpt, content_markdown = excluded.content_markdown,
is_published = excluded.is_published, published_at = excluded.published_at,
order_index = excluded.order_index,
updated_at = COALESCE(excluded.updated_at, CURRENT_TIMESTAMP)"#,
)
.bind(&item.id)
.bind(&item.page_id)
.bind(&item.title)
.bind(&item.slug)
.bind(&item.excerpt)
.bind(&item.content_markdown)

.bind(if item.is_published { 1 } else { 0 })
.bind(&item.published_at)
.bind(item.order_index)
Expand Down
Loading