Unverified Commit 5251e2e0 authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Add a new post

parent a49e9391
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import (
	"path"
	"strings"
	"text/template"
	"time"

	"git.lyda.ie/kevin/bulletin/ask"
	"git.lyda.ie/kevin/bulletin/key"
@@ -20,6 +21,9 @@ import (
//go:embed crontab
var crontabTemplate string

//go:embed announcement-2.06.txt
var announce206 string

// Reboot deletes all messages with `shutdown` set.
func Reboot() int {
	fmt.Println("TODO: Delete messages with shutdown != 0.")
@@ -64,11 +68,17 @@ func Install() int {
	ask.CheckErr(q.SeedUserSystem(ctx))
	ask.CheckErr(q.SeedFolderGeneral(ctx))
	ask.CheckErr(q.SeedGeneralOwner(ctx))
	ask.CheckErr(q.SeedCreateMessage(ctx, storage.SeedCreateMessageParams{
		Folder:     "GENERAL",
		Folder_2:   "GENERAL",
		Subject:    "Announcing PFC BULLETIN 2.06",
		Message:    announce206,
		Expiration: time.Now(),
	}))
	_, err = q.AddUser(ctx, storage.AddUserParams{
		Login: login,
		Name:  name,
	})
	ask.CheckErr(q.SeedGeneralOwner(ctx))
	key.Add(login, sshkey)

	// Install crontab.
+8 −0
Original line number Diff line number Diff line
@@ -8,3 +8,11 @@

-- name: SeedGeneralOwner :exec
  INSERT INTO owners (folder, login) VALUES ('GENERAL', 'SYSTEM');

-- name: SeedCreateMessage :exec
INSERT INTO messages (
  id,
  folder, author, subject, message, permanent, expiration
) VALUES (
  (SELECT COALESCE(MAX(id), 0) + 1 FROM messages AS m WHERE m.folder = ?),
  ?, 'SYSTEM', ?, ?, 1, ?);
+29 −0
Original line number Diff line number Diff line
@@ -7,8 +7,37 @@ package storage

import (
	"context"
	"time"
)

const seedCreateMessage = `-- name: SeedCreateMessage :exec
INSERT INTO messages (
  id,
  folder, author, subject, message, permanent, expiration
) VALUES (
  (SELECT COALESCE(MAX(id), 0) + 1 FROM messages AS m WHERE m.folder = ?),
  ?, 'SYSTEM', ?, ?, 1, ?)
`

type SeedCreateMessageParams struct {
	Folder     string
	Folder_2   string
	Subject    string
	Message    string
	Expiration time.Time
}

func (q *Queries) SeedCreateMessage(ctx context.Context, arg SeedCreateMessageParams) error {
	_, err := q.db.ExecContext(ctx, seedCreateMessage,
		arg.Folder,
		arg.Folder_2,
		arg.Subject,
		arg.Message,
		arg.Expiration,
	)
	return err
}

const seedFolderGeneral = `-- name: SeedFolderGeneral :exec
  INSERT INTO folders (name, description, system, shownew)
         VALUES ('GENERAL', 'Default general bulletin folder.', 1, 1)