Consolidate Version Source
The consolidate
command helps you optimize and clean up your version source files. It performs several operations to make your version source more efficient and maintainable.
What Consolidation Does
When you run the consolidate command, it:
- Removes duplicate version definitions
- Merges related changes into single operations
- Optimizes the order of operations
- Creates a new, consolidated version source file
Usage
To consolidate a version source, run:
alphadb consolidate
You will be prompted to select a version source file if one is not specified.
Alternatively, you can specify the version source file directly:
alphadb consolidate --source path/to/version_source.json
Output
The consolidated version source will be saved as a new file with a timestamp appended to the original filename. For example, if your original file was schema.json
, the consolidated file might be named schema_240430_1430.json
.
Example
Given a version source with multiple versions:
{
"name": "example-db",
"version": [
{
"_id": "1.0.0",
"createtable": {
"users": {
"primary_key": "id",
"id": {
"type": "INT",
"a_i": true
},
"name": {
"type": "VARCHAR",
"length": 100
}
}
}
},
{
"_id": "1.1.0",
"altertable": {
"users": {
"addcolumn": {
"email": {
"type": "VARCHAR",
"length": 255,
"unique": true
}
}
}
}
}
]
}
After consolidation, the version source will be optimized to:
{
"name": "example-db",
"version": [
{
"_id": "1.1.0",
"createtable": {
"users": {
"primary_key": "id",
"id": {
"type": "INT",
"a_i": true
},
"name": {
"type": "VARCHAR",
"length": 100
},
"email": {
"type": "VARCHAR",
"length": 255,
"unique": true
}
}
}
}
]
}
Best Practices
- Always keep a backup of your original version source files
- Review the consolidated version source before using it
- Use consolidation when you have accumulated many small changes
- Consider consolidating before major releases
Notes
- The consolidation process is safe and non-destructive
- The original version source file is not modified
- The consolidated file maintains the same functionality as the original