| 866 | } |
| 867 | |
| 868 | func UpsertWorkdir(db *sql.DB, path, name, description, gitRemote string) error { |
| 869 | now := NowISO() |
| 870 | _, err := db.Exec(` |
| 871 | INSERT INTO workdirs (path, name, description, git_remote, last_used_at, created_at) |
| 872 | VALUES (?, ?, ?, ?, ?, ?) |
| 873 | ON CONFLICT(path) DO UPDATE SET |
| 874 | name = COALESCE(NULLIF(excluded.name, ''), workdirs.name), |
| 875 | description = COALESCE(NULLIF(excluded.description, ''), workdirs.description), |
| 876 | git_remote = COALESCE(NULLIF(excluded.git_remote, ''), workdirs.git_remote), |
| 877 | last_used_at = excluded.last_used_at |
| 878 | `, path, NullIfEmpty(name), NullIfEmpty(description), NullIfEmpty(gitRemote), now, now) |
| 879 | if err != nil { |
| 880 | return fmt.Errorf("upsert workdir %s: %w", path, err) |
| 881 | } |
| 882 | return nil |
| 883 | } |
| 884 | |
| 885 | // ---------- playbook models ---------- |
| 886 | |