CREATE TABLE IF NOT EXISTS "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY);
CREATE TABLE IF NOT EXISTS "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL);
CREATE TABLE IF NOT EXISTS "entries" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "category" integer DEFAULT 0 NOT NULL, "fi" varchar, "en" varchar, "sv" varchar, "no" varchar, "ru" varchar, "de" varchar, "notes" text, "verified" boolean DEFAULT FALSE NOT NULL, "created_by_id" integer, "updated_by_id" integer, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL, CONSTRAINT "fk_rails_367d1ab731"
FOREIGN KEY ("created_by_id")
  REFERENCES "users" ("id")
, CONSTRAINT "fk_rails_6f84c41258"
FOREIGN KEY ("updated_by_id")
  REFERENCES "users" ("id")
);
CREATE INDEX "index_entries_on_created_by_id" ON "entries" ("created_by_id") /*application='SanastoWiki'*/;
CREATE INDEX "index_entries_on_updated_by_id" ON "entries" ("updated_by_id") /*application='SanastoWiki'*/;
CREATE INDEX "index_entries_on_category" ON "entries" ("category") /*application='SanastoWiki'*/;
CREATE TABLE IF NOT EXISTS "comments" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "user_id" integer NOT NULL, "commentable_type" varchar NOT NULL, "commentable_id" integer NOT NULL, "body" text NOT NULL, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL, "language_code" varchar /*application='SanastoWiki'*/, CONSTRAINT "fk_rails_03de2dc08c"
FOREIGN KEY ("user_id")
  REFERENCES "users" ("id")
);
CREATE INDEX "index_comments_on_user_id" ON "comments" ("user_id") /*application='SanastoWiki'*/;
CREATE INDEX "index_comments_on_commentable" ON "comments" ("commentable_type", "commentable_id") /*application='SanastoWiki'*/;
CREATE TABLE IF NOT EXISTS "supported_languages" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "code" varchar NOT NULL, "name" varchar NOT NULL, "native_name" varchar NOT NULL, "sort_order" integer DEFAULT 0 NOT NULL, "active" boolean DEFAULT TRUE NOT NULL, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL);
CREATE UNIQUE INDEX "index_supported_languages_on_code" ON "supported_languages" ("code") /*application='SanastoWiki'*/;
CREATE TABLE IF NOT EXISTS "users" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar NOT NULL, "password_digest" varchar NOT NULL, "name" varchar, "role" integer DEFAULT 0 NOT NULL, "primary_language" varchar, "invitation_token" varchar, "invitation_sent_at" datetime(6), "invitation_accepted_at" datetime(6), "invited_by_id" integer, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL, CONSTRAINT "fk_rails_ae14a5013f"
FOREIGN KEY ("invited_by_id")
  REFERENCES "users" ("id")
);
CREATE INDEX "index_users_on_invited_by_id" ON "users" ("invited_by_id") /*application='SanastoWiki'*/;
CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email") /*application='SanastoWiki'*/;
CREATE UNIQUE INDEX "index_users_on_invitation_token" ON "users" ("invitation_token") /*application='SanastoWiki'*/;
CREATE TABLE IF NOT EXISTS "suggested_meanings" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "entry_id" integer NOT NULL, "language_code" varchar NOT NULL, "alternative_translation" varchar NOT NULL, "context" text, "reasoning" text, "source" varchar, "region" varchar, "status" integer DEFAULT 0 NOT NULL, "submitted_by_id" integer NOT NULL, "reviewed_by_id" integer, "reviewed_at" datetime(6), "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL, CONSTRAINT "fk_rails_ef8b9af505"
FOREIGN KEY ("reviewed_by_id")
  REFERENCES "users" ("id")
, CONSTRAINT "fk_rails_c971e5e710"
FOREIGN KEY ("submitted_by_id")
  REFERENCES "users" ("id")
, CONSTRAINT "fk_rails_3b2160e218"
FOREIGN KEY ("entry_id")
  REFERENCES "entries" ("id")
, CONSTRAINT "fk_rails_1050c43426"
FOREIGN KEY ("language_code")
  REFERENCES "supported_languages" ("code")
);
CREATE INDEX "index_suggested_meanings_on_entry_id" ON "suggested_meanings" ("entry_id") /*application='SanastoWiki'*/;
CREATE INDEX "index_suggested_meanings_on_submitted_by_id" ON "suggested_meanings" ("submitted_by_id") /*application='SanastoWiki'*/;
CREATE INDEX "index_suggested_meanings_on_reviewed_by_id" ON "suggested_meanings" ("reviewed_by_id") /*application='SanastoWiki'*/;
CREATE INDEX "index_suggested_meanings_on_language_code" ON "suggested_meanings" ("language_code") /*application='SanastoWiki'*/;
CREATE INDEX "index_suggested_meanings_on_status" ON "suggested_meanings" ("status") /*application='SanastoWiki'*/;
CREATE VIRTUAL TABLE entries_fts USING fts5(
  fi,
  en,
  sv,
  no,
  ru,
  de,
  notes,
  content='entries',
  content_rowid='id'
)
/* entries_fts(fi,en,sv,"no",ru,de,notes) */;
CREATE TABLE IF NOT EXISTS 'entries_fts_data'(id INTEGER PRIMARY KEY, block BLOB);
CREATE TABLE IF NOT EXISTS 'entries_fts_idx'(segid, term, pgno, PRIMARY KEY(segid, term)) WITHOUT ROWID;
CREATE TABLE IF NOT EXISTS 'entries_fts_docsize'(id INTEGER PRIMARY KEY, sz BLOB);
CREATE TABLE IF NOT EXISTS 'entries_fts_config'(k PRIMARY KEY, v) WITHOUT ROWID;
CREATE TRIGGER entries_fts_after_insert
AFTER INSERT ON entries
BEGIN
  INSERT INTO entries_fts(rowid, fi, en, sv, no, ru, de, notes)
  VALUES (new.id, new.fi, new.en, new.sv, new.no, new.ru, new.de, new.notes);
END;
CREATE TRIGGER entries_fts_after_update
AFTER UPDATE ON entries
BEGIN
  INSERT INTO entries_fts(entries_fts, rowid, fi, en, sv, no, ru, de, notes)
  VALUES('delete', old.id, old.fi, old.en, old.sv, old.no, old.ru, old.de, old.notes);
  INSERT INTO entries_fts(rowid, fi, en, sv, no, ru, de, notes)
  VALUES (new.id, new.fi, new.en, new.sv, new.no, new.ru, new.de, new.notes);
END;
CREATE TRIGGER entries_fts_after_delete
AFTER DELETE ON entries
BEGIN
  INSERT INTO entries_fts(entries_fts, rowid, fi, en, sv, no, ru, de, notes)
  VALUES('delete', old.id, old.fi, old.en, old.sv, old.no, old.ru, old.de, old.notes);
END;
CREATE TABLE IF NOT EXISTS "setup_states" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "installed" boolean DEFAULT FALSE NOT NULL, "installed_at" datetime(6), "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL);
INSERT INTO "schema_migrations" (version) VALUES
('20260123130957'),
('20260123125325'),
('20260122131000'),
('20260122130000'),
('20260122124151'),
('20260122123837'),
('20260122123833'),
('20260122123831'),
('20260122123828'),
('20260122123822'),
('20260122123818'),
('0');

