From 47c1beadcd4ffb2025c441d3b6151db296eb235e Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Date: Wed, 27 Aug 2025 13:09:15 -0700 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20sqlite=20support?= =?UTF-8?q?=20to=20host-catalogs=20(#2973)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-17417 --- addons/api/addon/services/sqlite.js | 10 +++++++ addons/api/addon/workers/utils/schema.js | 38 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/addons/api/addon/services/sqlite.js b/addons/api/addon/services/sqlite.js index 775cec1dd..07a292530 100644 --- a/addons/api/addon/services/sqlite.js +++ b/addons/api/addon/services/sqlite.js @@ -74,6 +74,15 @@ export const modelMapping = { scope_id: 'scope.scope_id', created_time: 'created_time', }, + 'host-catalog': { + id: 'id', + type: 'type', + name: 'name', + description: 'description', + plugin_name: 'plugin.name', + scope_id: 'scope.scope_id', + created_time: 'created_time', + }, }; // A list of tables that we support searching using FTS5 in SQLite. @@ -86,6 +95,7 @@ export const searchTables = new Set([ 'credential-store', 'scope', 'auth-method', + 'host-catalog', ]); export default class SqliteDbService extends Service { diff --git a/addons/api/addon/workers/utils/schema.js b/addons/api/addon/workers/utils/schema.js index ca61f343a..4603c10cf 100644 --- a/addons/api/addon/workers/utils/schema.js +++ b/addons/api/addon/workers/utils/schema.js @@ -300,6 +300,43 @@ CREATE TRIGGER IF NOT EXISTS auth_method_ad AFTER DELETE ON auth_method BEGIN VALUES('delete', old.rowid, old.id, old.type, old.name, old.description, old.is_primary, old.scope_id, old.created_time); END;`; +const createHostCatalogTables = ` +CREATE TABLE IF NOT EXISTS host_catalog ( + id TEXT NOT NULL PRIMARY KEY, + type TEXT NOT NULL, + name TEXT, + description TEXT, + plugin_name TEXT, + scope_id TEXT NOT NULL, + created_time TEXT NOT NULL, + data TEXT NOT NULL +); +CREATE INDEX IF NOT EXISTS idx_host_catalog_scope_id_created_time ON host_catalog(scope_id, created_time DESC); + +CREATE VIRTUAL TABLE IF NOT EXISTS host_catalog_fts USING fts5( + id, + type, + name, + description, + plugin_name, + scope_id, + created_time, + content='', +); + +CREATE TRIGGER IF NOT EXISTS host_catalog_ai AFTER INSERT ON host_catalog BEGIN + INSERT INTO host_catalog_fts( + id, type, name, description, plugin_name, scope_id, created_time + ) VALUES ( + new.id, new.type, new.name, new.description, new.plugin_name, new.scope_id, new.created_time + ); +END; + +CREATE TRIGGER IF NOT EXISTS host_catalog_ad AFTER DELETE ON host_catalog BEGIN + INSERT INTO host_catalog_fts(host_catalog_fts, rowid, id, type, name, description, plugin_name, scope_id, created_time) + VALUES('delete', old.rowid, old.id, old.type, old.name, old.description, old.plugin_name, old.scope_id, old.created_time); +END;`; + export const CREATE_TABLES = (version) => ` BEGIN; @@ -318,6 +355,7 @@ ${createUserTables} ${createCredentialStoreTables} ${createScopeTables} ${createAuthMethodTables} +${createHostCatalogTables} COMMIT;`;