Add Configuration Option to Include Generated Columns #485
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Configuration Option to Include Generated Columns
Overview
Added a new configuration key
include-generated-columns(or environment variableDB_DUMP_INCLUDE_GENERATED_COLUMNS) to allow users to control whether generated columns should be included in database dumps.Problem
Previously, the code would always exclude columns marked as
VIRTUALorGENERATEDin the "Extra" field of MySQL'sSHOW COLUMNSoutput. This was hardcoded behavior with no way to override it.Solution
Implemented a configurable option to control this behavior by:
IncludeGeneratedColumnsboolean field throughout the configuration chainFiles Modified
1.
pkg/database/mysql/dump.goIncludeGeneratedColumns boolfield to theDatastruct2.
pkg/database/mysql/table.goinitColumnData()function to useIncludeGeneratedColumnssettingGENERATEDorVIRTUALwere always excludedVIRTUALare always excluded (computed columns that can't be stored)GENERATEDare excluded UNLESSIncludeGeneratedColumnsistrue3.
pkg/database/dump.goIncludeGeneratedColumns booltoDumpOptsstructDump()function to pass this setting tomysql.Data4.
pkg/core/dumpoptions.goIncludeGeneratedColumns booltoDumpOptionsstruct5.
pkg/core/dump.goDump()function to includeIncludeGeneratedColumnswhen creatingdatabase.DumpOpts6.
cmd/dump.go--include-generated-columnsCLI flag (boolean, defaults to false)includeGeneratedColumnsvariable to the command execution pathcore.DumpOptionsstructUsage
Command Line
Default Behavior
By default (
--include-generated-columnsis not set), the behavior is unchanged:VIRTUALcolumns are excludedGENERATEDcolumns are excludedWith the Flag
When
--include-generated-columnsis set:VIRTUALcolumns are still excluded (they cannot be restored)GENERATEDcolumns are included in the dumpEnvironment Variable
The setting can also be controlled via environment variable:
DB_DUMP_INCLUDE_GENERATED_COLUMNStrueorfalseexport DB_DUMP_INCLUDE_GENERATED_COLUMNS=trueNotes
api.Dumptype in the databacker/api repositoryVIRTUALcolumns are always excluded as they cannot be dumped and restored