import 'tables.dart';

-- This table was added in schema version 3
CREATE TABLE "groups" (
    id INTEGER NOT NULL,
    title TEXT NOT NULL,
    deleted BOOLEAN DEFAULT FALSE,
    owner INTEGER NOT NULL REFERENCES users (id),

    PRIMARY KEY (id)
);

-- This table was added in schema version 7
CREATE VIRTUAL TABLE notes USING fts5(
    title,
    content,
    search_terms,
    tokenize = "unicode61 tokenchars '.'"
);

-- This view was added in schema version 5
CREATE VIEW group_count AS SELECT
    users.*,
    (SELECT COUNT(*) FROM "groups" WHERE owner = users.id) AS group_count
  FROM users;
