/**
 * Applies the schema for untracked state storage.
 *
 * Untracked state bypasses change control and is stored directly
 * without creating change records. This is used for temporary state,
 * configuration, and other data that doesn't need version history.
 */
export function applyUntrackedStateSchema(args) {
    args.engine.sqlite.exec(`
		-- Table for untracked state that bypasses change control
		CREATE TABLE IF NOT EXISTS lix_internal_state_all_untracked (
			entity_id TEXT NOT NULL,
			schema_key TEXT NOT NULL,
			file_id TEXT NOT NULL,
			version_id TEXT NOT NULL,
			plugin_key TEXT NOT NULL,
			snapshot_content BLOB, -- JSONB content, NULL for tombstones
			schema_version TEXT NOT NULL,
			created_at TEXT NOT NULL CHECK (created_at LIKE '%Z'),
			updated_at TEXT NOT NULL CHECK (updated_at LIKE '%Z'),
			inherited_from_version_id TEXT, -- Track inheritance source
			is_tombstone INTEGER DEFAULT 0 CHECK (is_tombstone IN (0, 1)), -- Flag for tombstones (1 = tombstone, 0 = normal)
			PRIMARY KEY (entity_id, schema_key, file_id, version_id),
			-- 8 = strictly JSONB
			-- https://www.sqlite.org/json1.html#jvalid
			CHECK (snapshot_content IS NULL OR json_valid(snapshot_content, 8)),
			-- Ensure content is either NULL or a JSON object (not string, array, etc)
			-- This prevents double-stringified JSON from being stored
			CHECK (snapshot_content IS NULL OR json_type(snapshot_content) = 'object'),
			-- Validation: if is_tombstone is 1, snapshot_content must be NULL
			CHECK (
				(is_tombstone = 1 AND snapshot_content IS NULL) OR
				(is_tombstone = 0)
			)
		) STRICT;

		-- Index for fast version_id filtering
		CREATE INDEX IF NOT EXISTS idx_lix_internal_state_all_untracked_version_id 
			ON lix_internal_state_all_untracked (version_id);

		CREATE INDEX IF NOT EXISTS ix_unt_v_f_s_e
			ON lix_internal_state_all_untracked (version_id, file_id, schema_key, entity_id);
	`);
}
//# sourceMappingURL=schema.js.map