Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
99 lines
1.5 KiB
Go
99 lines
1.5 KiB
Go
package db
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"database/sql"
|
|
"encoding/hex"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func Bootstrap(
|
|
database *sql.DB,
|
|
) error {
|
|
|
|
var count int
|
|
|
|
err := database.QueryRow(`
|
|
SELECT count(*)
|
|
FROM objects
|
|
`).Scan(&count)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if count > 0 {
|
|
return nil
|
|
}
|
|
|
|
rootUUID :=
|
|
uuid.NewString()
|
|
|
|
rootBody :=
|
|
"<h1>Pages Wiki</h1><p>Bootstrap complete.</p>"
|
|
|
|
rootBodySum :=
|
|
sha256.Sum256(
|
|
[]byte(rootBody),
|
|
)
|
|
|
|
_, err = database.Exec(`
|
|
INSERT INTO objects ( uuid, created_at ) VALUES ( ?, strftime('%s','now') )`,
|
|
rootUUID,
|
|
)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = database.Exec(`
|
|
INSERT INTO paths (
|
|
path,
|
|
object_uuid,
|
|
created_at
|
|
)
|
|
VALUES (
|
|
'/',
|
|
?,
|
|
strftime('%s','now')
|
|
)
|
|
`,
|
|
rootUUID,
|
|
)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = database.Exec(`
|
|
INSERT INTO revisions (
|
|
uuid,
|
|
object_uuid,
|
|
body,
|
|
document_hash,
|
|
lang,
|
|
message,
|
|
created_at_ms,
|
|
created_at
|
|
)
|
|
VALUES (
|
|
?,
|
|
?,
|
|
?,
|
|
?,
|
|
'und',
|
|
'bootstrap',
|
|
CAST(strftime('%s','now') AS INTEGER) * 1000,
|
|
strftime('%s','now')
|
|
)
|
|
`,
|
|
uuid.NewString(),
|
|
rootUUID,
|
|
rootBody,
|
|
hex.EncodeToString(rootBodySum[:]),
|
|
)
|
|
|
|
return err
|
|
}
|