From 9b36a35c1a0ef455376482c6c63d8405cfac2892 Mon Sep 17 00:00:00 2001 From: Leon Mika Date: Sun, 22 Mar 2026 14:26:09 +1100 Subject: [PATCH] feat: add posts_per_page column to sites table Co-Authored-By: Claude Sonnet 4.6 --- providers/db/gen/sqlgen/models.go | 15 ++++++----- providers/db/gen/sqlgen/sites.sql.go | 38 +++++++++++++++++----------- sql/queries/sites.sql | 5 ++-- sql/schema/05_posts_per_page.up.sql | 1 + 4 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 sql/schema/05_posts_per_page.up.sql diff --git a/providers/db/gen/sqlgen/models.go b/providers/db/gen/sqlgen/models.go index 788c292..ae58594 100644 --- a/providers/db/gen/sqlgen/models.go +++ b/providers/db/gen/sqlgen/models.go @@ -57,13 +57,14 @@ type PublishTarget struct { } type Site struct { - ID int64 - OwnerID int64 - Guid string - Title string - Tagline string - CreatedAt int64 - Timezone string + ID int64 + OwnerID int64 + Guid string + Title string + Tagline string + CreatedAt int64 + Timezone string + PostsPerPage int64 } type Upload struct { diff --git a/providers/db/gen/sqlgen/sites.sql.go b/providers/db/gen/sqlgen/sites.sql.go index bd80fb3..80ccbc0 100644 --- a/providers/db/gen/sqlgen/sites.sql.go +++ b/providers/db/gen/sqlgen/sites.sql.go @@ -28,18 +28,20 @@ INSERT INTO sites ( title, tagline, timezone, + posts_per_page, created_at -) VALUES (?, ?, ?, ?, ?, ?) +) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id ` type InsertSiteParams struct { - OwnerID int64 - Guid string - Title string - Tagline string - Timezone string - CreatedAt int64 + OwnerID int64 + Guid string + Title string + Tagline string + Timezone string + PostsPerPage int64 + CreatedAt int64 } func (q *Queries) InsertSite(ctx context.Context, arg InsertSiteParams) (int64, error) { @@ -49,6 +51,7 @@ func (q *Queries) InsertSite(ctx context.Context, arg InsertSiteParams) (int64, arg.Title, arg.Tagline, arg.Timezone, + arg.PostsPerPage, arg.CreatedAt, ) var id int64 @@ -101,7 +104,7 @@ func (q *Queries) SelectAllSitesWithOwners(ctx context.Context) ([]SelectAllSite } const selectSiteByGUID = `-- name: SelectSiteByGUID :one -SELECT id, owner_id, guid, title, tagline, created_at, timezone FROM sites WHERE guid = ? +SELECT id, owner_id, guid, title, tagline, created_at, timezone, posts_per_page FROM sites WHERE guid = ? ` func (q *Queries) SelectSiteByGUID(ctx context.Context, guid string) (Site, error) { @@ -115,12 +118,13 @@ func (q *Queries) SelectSiteByGUID(ctx context.Context, guid string) (Site, erro &i.Tagline, &i.CreatedAt, &i.Timezone, + &i.PostsPerPage, ) return i, err } const selectSiteByID = `-- name: SelectSiteByID :one -SELECT id, owner_id, guid, title, tagline, created_at, timezone FROM sites WHERE id = ? +SELECT id, owner_id, guid, title, tagline, created_at, timezone, posts_per_page FROM sites WHERE id = ? ` func (q *Queries) SelectSiteByID(ctx context.Context, id int64) (Site, error) { @@ -134,12 +138,13 @@ func (q *Queries) SelectSiteByID(ctx context.Context, id int64) (Site, error) { &i.Tagline, &i.CreatedAt, &i.Timezone, + &i.PostsPerPage, ) return i, err } const selectSitesOwnedByUser = `-- name: SelectSitesOwnedByUser :many -SELECT id, owner_id, guid, title, tagline, created_at, timezone FROM sites WHERE owner_id = ? ORDER BY title ASC +SELECT id, owner_id, guid, title, tagline, created_at, timezone, posts_per_page FROM sites WHERE owner_id = ? ORDER BY title ASC ` func (q *Queries) SelectSitesOwnedByUser(ctx context.Context, ownerID int64) ([]Site, error) { @@ -159,6 +164,7 @@ func (q *Queries) SelectSitesOwnedByUser(ctx context.Context, ownerID int64) ([] &i.Tagline, &i.CreatedAt, &i.Timezone, + &i.PostsPerPage, ); err != nil { return nil, err } @@ -174,14 +180,15 @@ func (q *Queries) SelectSitesOwnedByUser(ctx context.Context, ownerID int64) ([] } const updateSite = `-- name: UpdateSite :exec -UPDATE sites SET title = ?, tagline = ?, timezone = ? WHERE id = ? +UPDATE sites SET title = ?, tagline = ?, timezone = ?, posts_per_page = ? WHERE id = ? ` type UpdateSiteParams struct { - Title string - Tagline string - Timezone string - ID int64 + Title string + Tagline string + Timezone string + PostsPerPage int64 + ID int64 } func (q *Queries) UpdateSite(ctx context.Context, arg UpdateSiteParams) error { @@ -189,6 +196,7 @@ func (q *Queries) UpdateSite(ctx context.Context, arg UpdateSiteParams) error { arg.Title, arg.Tagline, arg.Timezone, + arg.PostsPerPage, arg.ID, ) return err diff --git a/sql/queries/sites.sql b/sql/queries/sites.sql index 8fe2469..0609b12 100644 --- a/sql/queries/sites.sql +++ b/sql/queries/sites.sql @@ -14,15 +14,16 @@ INSERT INTO sites ( title, tagline, timezone, + posts_per_page, created_at -) VALUES (?, ?, ?, ?, ?, ?) +) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING id; -- name: HasUsersAndSites :one SELECT (SELECT COUNT(*) FROM users) > 0 AND (SELECT COUNT(*) FROM sites) > 0 AS has_users_and_sites; -- name: UpdateSite :exec -UPDATE sites SET title = ?, tagline = ?, timezone = ? WHERE id = ?; +UPDATE sites SET title = ?, tagline = ?, timezone = ?, posts_per_page = ? WHERE id = ?; -- name: SelectAllSitesWithOwners :many SELECT s.id, s.guid, s.title, s.owner_id, u.username diff --git a/sql/schema/05_posts_per_page.up.sql b/sql/schema/05_posts_per_page.up.sql new file mode 100644 index 0000000..1bea8f9 --- /dev/null +++ b/sql/schema/05_posts_per_page.up.sql @@ -0,0 +1 @@ +ALTER TABLE sites ADD COLUMN posts_per_page INTEGER NOT NULL DEFAULT 10;