Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internal/cli/discourse_reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ func buildAssetsClobberCommands() []string {
)
}

// buildSchemaCacheClearCommands generates commands to remove any cached schema
// YAML files after a branch switch. The cache is tied to a specific schema
// version; leaving it in place after switching branches causes Rails to
// misread column types (e.g. boolean instead of integer defaults), which
// crashes boot before assets:clobber or migrations can run.
func buildSchemaCacheClearCommands() []string {
return []string{
"echo 'Clearing stale schema cache...'",
"find . -name 'schema_cache.yml*' -delete 2>/dev/null || true",
}
}

// buildDatabaseDropCreateMigrateCommands generates commands to drop, create, and migrate databases.
// When skipDBReset is true, db:drop and db:create are omitted, as well as user seeding.
// Only migrations and later steps run.
Expand Down Expand Up @@ -168,6 +180,9 @@ func buildDiscourseResetScript(checkoutCmds []string, opts discourseResetScriptO
// Post-checkout steps
lines = append(lines, buildPostCheckoutCommands()...)

// Schema cache must be cleared before Rails boots on the new branch
lines = append(lines, buildSchemaCacheClearCommands()...)

// Rails asset cleanup
lines = append(lines, buildAssetsClobberCommands()...)

Expand Down
7 changes: 5 additions & 2 deletions internal/cli/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,15 @@ git fetch origin "$_branch" --tags --prune --force
git checkout -B "$_branch" "origin/$_branch"
git reset --hard "origin/$_branch"
%s
`, shellQuote(branchName), strings.Join(buildAssetsClobberCommands(), "\n"))
%s
`, shellQuote(branchName), strings.Join(buildSchemaCacheClearCommands(), "\n"), strings.Join(buildAssetsClobberCommands(), "\n"))
return docker.ExecInteractive(name, workdir, envs, []string{"bash", "-lc", script})
}

func checkoutBranch(cmd *cobra.Command, cfg config.Config, name, workdir, branchName string, envs docker.Envs, withoutTestDB bool) error {
if branchName == "main" || branchName == "master" {
fmt.Fprintf(cmd.OutOrStdout(), "Updating %s branch...\n", branchName)
schemaClearCmds := strings.Join(buildSchemaCacheClearCommands(), "\n")
assetClobberCmds := strings.Join(buildAssetsClobberCommands(), "\n")
script := fmt.Sprintf(`
set -e
Expand All @@ -552,7 +554,8 @@ git checkout %s > /tmp/dv-git-checkout.log 2>&1
echo "Pulling latest..."
git pull > /tmp/dv-git-pull.log 2>&1
%s
`, branchName, branchName, assetClobberCmds)
%s
`, branchName, branchName, schemaClearCmds, assetClobberCmds)
return docker.ExecInteractive(name, workdir, envs, []string{"bash", "-lc", script})
}
checkoutCmds := buildBranchCheckoutCommands(branchName)
Expand Down
Loading