mast/db/migrations.go
aynish d46d67830a Sync implementation using cr-sqlite + websockets, across JS and CLI clients (#1)
- Implements CRDT syncing using cr-slqlite.
- Initializes a simple vite application from the cr-sqlite repos that uses Svelte
- implements a websocket go server backend for communicating syncs between applications

Needs lots of refactoring, everything is hardcoded

Co-authored-by: Anish Lakhwara <anish+git@lakhwara.com>
Reviewed-on: #1
2024-08-31 18:06:10 -07:00

25 lines
586 B
Go

package mast
import (
"database/sql"
)
func RunMigrations(db *sql.DB) error {
// Load the cr-sqlite extension
// _, err := db.Exec("SELECT load_extension('./crsqlite.so', 'sqlite3_crsqlite_init')")
// if err != nil {
// return fmt.Errorf("failed to load cr-sqlite extension: %w", err)
// }
// Create the todos table and initialize it as a CRDT
_, err := db.Exec(`
CREATE TABLE IF NOT EXISTS todos (id blob PRIMARY KEY NOT NULL, content TEXT, completed INTEGER NOT NULL DEFAULT 0);
SELECT crsql_as_crr('todos');
`)
if err != nil {
return err
}
return nil
}