Add show_hidden_files filed to workspace

This commit is contained in:
2024-11-11 22:24:27 +01:00
parent f3f3cb7371
commit bac4702771
4 changed files with 20 additions and 11 deletions

View File

@@ -59,6 +59,9 @@ var migrations = []Migration{
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
);
-- Add show_hidden_files field to workspaces
ALTER TABLE workspaces ADD COLUMN show_hidden_files BOOLEAN NOT NULL DEFAULT 0;
-- Add indexes for performance
CREATE INDEX idx_sessions_user_id ON sessions(user_id);
CREATE INDEX idx_sessions_expires_at ON sessions(expires_at);

View File

@@ -66,12 +66,12 @@ func (db *DB) createWorkspaceTx(tx *sql.Tx, workspace *models.Workspace) error {
result, err := tx.Exec(`
INSERT INTO workspaces (
user_id, name,
theme, auto_save,
theme, auto_save, show_hidden_files,
git_enabled, git_url, git_user, git_token,
git_auto_commit, git_commit_msg_template
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
workspace.UserID, workspace.Name,
workspace.Theme, workspace.AutoSave,
workspace.Theme, workspace.AutoSave, workspace.ShowHiddenFiles,
workspace.GitEnabled, workspace.GitURL, workspace.GitUser, workspace.GitToken,
workspace.GitAutoCommit, workspace.GitCommitMsgTemplate,
)

View File

@@ -21,11 +21,11 @@ func (db *DB) CreateWorkspace(workspace *models.Workspace) error {
result, err := db.Exec(`
INSERT INTO workspaces (
user_id, name, theme, auto_save,
user_id, name, theme, auto_save, show_hidden_files,
git_enabled, git_url, git_user, git_token,
git_auto_commit, git_commit_msg_template
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
workspace.UserID, workspace.Name, workspace.Theme, workspace.AutoSave,
workspace.UserID, workspace.Name, workspace.Theme, workspace.AutoSave, workspace.ShowHiddenFiles,
workspace.GitEnabled, workspace.GitURL, workspace.GitUser, encryptedToken,
workspace.GitAutoCommit, workspace.GitCommitMsgTemplate,
)
@@ -49,7 +49,7 @@ func (db *DB) GetWorkspaceByID(id int) (*models.Workspace, error) {
err := db.QueryRow(`
SELECT
id, user_id, name, created_at,
theme, auto_save,
theme, auto_save, show_hidden_files,
git_enabled, git_url, git_user, git_token,
git_auto_commit, git_commit_msg_template
FROM workspaces
@@ -57,7 +57,7 @@ func (db *DB) GetWorkspaceByID(id int) (*models.Workspace, error) {
id,
).Scan(
&workspace.ID, &workspace.UserID, &workspace.Name, &workspace.CreatedAt,
&workspace.Theme, &workspace.AutoSave,
&workspace.Theme, &workspace.AutoSave, &workspace.ShowHiddenFiles,
&workspace.GitEnabled, &workspace.GitURL, &workspace.GitUser, &encryptedToken,
&workspace.GitAutoCommit, &workspace.GitCommitMsgTemplate,
)
@@ -82,7 +82,7 @@ func (db *DB) GetWorkspaceByName(userID int, workspaceName string) (*models.Work
err := db.QueryRow(`
SELECT
id, user_id, name, created_at,
theme, auto_save,
theme, auto_save, show_hidden_files,
git_enabled, git_url, git_user, git_token,
git_auto_commit, git_commit_msg_template
FROM workspaces
@@ -90,7 +90,7 @@ func (db *DB) GetWorkspaceByName(userID int, workspaceName string) (*models.Work
userID, workspaceName,
).Scan(
&workspace.ID, &workspace.UserID, &workspace.Name, &workspace.CreatedAt,
&workspace.Theme, &workspace.AutoSave,
&workspace.Theme, &workspace.AutoSave, &workspace.ShowHiddenFiles,
&workspace.GitEnabled, &workspace.GitURL, &workspace.GitUser, &encryptedToken,
&workspace.GitAutoCommit, &workspace.GitCommitMsgTemplate,
)
@@ -121,6 +121,7 @@ func (db *DB) UpdateWorkspace(workspace *models.Workspace) error {
name = ?,
theme = ?,
auto_save = ?,
show_hidden_files = ?,
git_enabled = ?,
git_url = ?,
git_user = ?,
@@ -131,6 +132,7 @@ func (db *DB) UpdateWorkspace(workspace *models.Workspace) error {
workspace.Name,
workspace.Theme,
workspace.AutoSave,
workspace.ShowHiddenFiles,
workspace.GitEnabled,
workspace.GitURL,
workspace.GitUser,
@@ -166,7 +168,7 @@ func (db *DB) GetWorkspacesByUserID(userID int) ([]*models.Workspace, error) {
var encryptedToken string
err := rows.Scan(
&workspace.ID, &workspace.UserID, &workspace.Name, &workspace.CreatedAt,
&workspace.Theme, &workspace.AutoSave,
&workspace.Theme, &workspace.AutoSave, &workspace.ShowHiddenFiles,
&workspace.GitEnabled, &workspace.GitURL, &workspace.GitUser, &encryptedToken,
&workspace.GitAutoCommit, &workspace.GitCommitMsgTemplate,
)
@@ -193,6 +195,7 @@ func (db *DB) UpdateWorkspaceSettings(workspace *models.Workspace) error {
SET
theme = ?,
auto_save = ?,
show_hidden_files = ?,
git_enabled = ?,
git_url = ?,
git_user = ?,
@@ -202,6 +205,7 @@ func (db *DB) UpdateWorkspaceSettings(workspace *models.Workspace) error {
WHERE id = ?`,
workspace.Theme,
workspace.AutoSave,
workspace.ShowHiddenFiles,
workspace.GitEnabled,
workspace.GitURL,
workspace.GitUser,
@@ -255,7 +259,7 @@ func (db *DB) GetAllWorkspaces() ([]*models.Workspace, error) {
rows, err := db.Query(`
SELECT
id, user_id, name, created_at,
theme, auto_save,
theme, auto_save, show_hidden_files,
git_enabled, git_url, git_user, git_token,
git_auto_commit, git_commit_msg_template
FROM workspaces`,
@@ -271,7 +275,7 @@ func (db *DB) GetAllWorkspaces() ([]*models.Workspace, error) {
var encryptedToken string
err := rows.Scan(
&workspace.ID, &workspace.UserID, &workspace.Name, &workspace.CreatedAt,
&workspace.Theme, &workspace.AutoSave,
&workspace.Theme, &workspace.AutoSave, &workspace.ShowHiddenFiles,
&workspace.GitEnabled, &workspace.GitURL, &workspace.GitUser, &encryptedToken,
&workspace.GitAutoCommit, &workspace.GitCommitMsgTemplate,
)

View File

@@ -14,6 +14,7 @@ type Workspace struct {
// Integrated settings
Theme string `json:"theme" validate:"oneof=light dark"`
AutoSave bool `json:"autoSave"`
ShowHiddenFiles bool `json:"showHiddenFiles"`
GitEnabled bool `json:"gitEnabled"`
GitURL string `json:"gitUrl" validate:"required_if=GitEnabled true"`
GitUser string `json:"gitUser" validate:"required_if=GitEnabled true"`
@@ -29,6 +30,7 @@ func (w *Workspace) Validate() error {
func (w *Workspace) GetDefaultSettings() {
w.Theme = "light"
w.AutoSave = false
w.ShowHiddenFiles = false
w.GitEnabled = false
w.GitURL = ""
w.GitUser = ""