62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/pocketbase/pocketbase/core"
|
|
)
|
|
|
|
// setupCollections creates the required collections for the event store
|
|
func setupCollections(app core.App) error {
|
|
// For PocketBase v0.30.0, collections are typically created through the admin UI
|
|
// or by using SQL migrations. This is a simplified approach that logs what needs to be done.
|
|
// In a real implementation, you'd either:
|
|
// 1. Create collections through the PocketBase admin UI
|
|
// 2. Use proper migration files
|
|
// 3. Use the SQL approach with app.DB()
|
|
|
|
// Execute SQL to create events table if it doesn't exist
|
|
_, err := app.DB().NewQuery(`
|
|
CREATE TABLE IF NOT EXISTS events (
|
|
id TEXT PRIMARY KEY,
|
|
seq INTEGER NOT NULL,
|
|
type TEXT NOT NULL,
|
|
hash TEXT NOT NULL,
|
|
item_id TEXT NOT NULL,
|
|
event_id TEXT NOT NULL,
|
|
collection TEXT NOT NULL,
|
|
data TEXT,
|
|
timestamp DATETIME NOT NULL,
|
|
created DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
updated DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
)
|
|
`).Execute()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Create index on sequence number for faster queries
|
|
_, err = app.DB().NewQuery(`
|
|
CREATE INDEX IF NOT EXISTS idx_events_seq ON events(seq)
|
|
`).Execute()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Execute SQL to create shopping_items table if it doesn't exist
|
|
_, err = app.DB().NewQuery(`
|
|
CREATE TABLE IF NOT EXISTS shopping_items (
|
|
id TEXT PRIMARY KEY,
|
|
content TEXT NOT NULL,
|
|
created_at DATETIME NOT NULL,
|
|
updated_at DATETIME NOT NULL,
|
|
deleted_at DATETIME,
|
|
created DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
updated DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
)
|
|
`).Execute()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|