Migration Adjustment (#256)

* Adjust migration behavior

* mct

* add blah.txt to gitignore

* fix incorrect import in hlyr

* Make hlyr version flag read from package.json

Previously the version was hardcoded in index.ts which could get out of
sync with package.json. Now it dynamically reads the version at runtime
to ensure they always match.

* prettier format
This commit is contained in:
Sundeep Malladi
2025-06-30 12:55:11 -05:00
committed by GitHub
parent 73312b3b78
commit 59a6e742a6
4 changed files with 55 additions and 21 deletions

2
.gitignore vendored
View File

@@ -178,3 +178,5 @@ cython_debug/
.Trashes
.idea/
hlyr/blah.txt

View File

@@ -179,21 +179,12 @@ func (s *SQLiteStore) initSchema() error {
return fmt.Errorf("failed to create schema: %w", err)
}
// Record initial schema version
// For new databases, we start at version 3 since the schema includes all fields
// Record initial schema version for new databases only
// Migration system will handle upgrading existing databases
_, err := s.db.Exec(`
INSERT OR IGNORE INTO schema_version (version, description)
VALUES (1, 'Initial schema with conversation events')
`)
if err != nil {
return err
}
// Mark new databases as having all migrations applied
_, err = s.db.Exec(`
INSERT OR IGNORE INTO schema_version (version, description)
VALUES (3, 'Initial schema includes all permission and tool fields')
`)
return err
}
@@ -213,15 +204,46 @@ func (s *SQLiteStore) applyMigrations() error {
if currentVersion < 3 {
slog.Info("Applying migration 3: Add permission and tool fields")
_, err := s.db.Exec(`
-- Add missing columns to sessions table
ALTER TABLE sessions ADD COLUMN permission_prompt_tool TEXT;
ALTER TABLE sessions ADD COLUMN append_system_prompt TEXT;
ALTER TABLE sessions ADD COLUMN allowed_tools TEXT;
ALTER TABLE sessions ADD COLUMN disallowed_tools TEXT;
`)
// Check if columns already exist (they might be in the schema for new databases)
var columnCount int
err = s.db.QueryRow(`
SELECT COUNT(*) FROM pragma_table_info('sessions')
WHERE name IN ('permission_prompt_tool', 'append_system_prompt', 'allowed_tools', 'disallowed_tools')
`).Scan(&columnCount)
if err != nil {
return fmt.Errorf("failed to apply migration 3: %w", err)
return fmt.Errorf("failed to check existing columns: %w", err)
}
// Only add columns if they don't exist
if columnCount < 4 {
// SQLite requires separate ALTER TABLE statements
alterations := []struct {
column string
sql string
}{
{"permission_prompt_tool", "ALTER TABLE sessions ADD COLUMN permission_prompt_tool TEXT"},
{"append_system_prompt", "ALTER TABLE sessions ADD COLUMN append_system_prompt TEXT"},
{"allowed_tools", "ALTER TABLE sessions ADD COLUMN allowed_tools TEXT"},
{"disallowed_tools", "ALTER TABLE sessions ADD COLUMN disallowed_tools TEXT"},
}
for _, alt := range alterations {
// Check if this specific column exists
var exists int
err = s.db.QueryRow(`
SELECT COUNT(*) FROM pragma_table_info('sessions') WHERE name = ?
`, alt.column).Scan(&exists)
if err != nil {
return fmt.Errorf("failed to check column %s: %w", alt.column, err)
}
if exists == 0 {
_, err := s.db.Exec(alt.sql)
if err != nil {
return fmt.Errorf("failed to add column %s: %w", alt.column, err)
}
}
}
}
// Record migration

View File

@@ -2,7 +2,7 @@ import dotenv from 'dotenv'
import fs from 'fs'
import path from 'path'
import chalk from 'chalk'
import { ContactChannel } from 'humanlayer'
import { ContactChannel } from '@humanlayer/sdk'
// Load environment variables
dotenv.config()

View File

@@ -2,6 +2,9 @@
import { Command } from 'commander'
import { spawn } from 'child_process'
import { readFileSync } from 'fs'
import { fileURLToPath } from 'url'
import { dirname, join } from 'path'
import { loginCommand } from './commands/login.js'
import { tuiCommand } from './commands/tui.js'
import { contactHumanCommand } from './commands/contactHuman.js'
@@ -20,6 +23,10 @@ import {
import { getProject } from './hlClient.js'
import chalk from 'chalk'
// Read version from package.json
const __dirname = dirname(fileURLToPath(import.meta.url))
const packageJson = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'))
function showAbbreviatedConfig() {
const configWithSources = resolveConfigWithSources({})
console.log(`\n${chalk.yellow('Current configuration:')}`)
@@ -62,7 +69,10 @@ async function authenticate(printSelectedProject: boolean = false) {
}
}
program.name('humanlayer').description('HumanLayer, but on your command-line.').version('0.7.0')
program
.name('humanlayer')
.description('HumanLayer, but on your command-line.')
.version(packageJson.version)
const UNPROTECTED_COMMANDS = ['config', 'login', 'thoughts']