Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from schemahero/table-schema-test
Table schema test
- Loading branch information
Showing
27 changed files
with
434 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ignore: | ||
- "**/zz_generated.deepcopy.go" # Ignore generated deepcopy code from kubebuilder | ||
- "pkg/client/schemaheroclientset/**/*.go" # Ignore generated code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Desired Schema Management | ||
|
||
There are many benefits to managing database schemas as code, including: | ||
1. Ability to adhere to a change management process | ||
2. Repeatable deployments to new environments | ||
... | ||
|
||
## Current Tools | ||
|
||
There are several commonly-used methods of managing database schemas employed today. | ||
|
||
1. Sequencial Migrations / Replay (Convergence) | ||
1. Declarative Schema Management | ||
|
||
### Sequential Migrations / Replay | ||
|
||
Tools such as db-migrate, Flyaway, goose and others fit into this category. These are immutable after deployment, stacked migrations that start from an empty database and consist of ordered create, alter and drop commands. | ||
|
||
#### Challenges | ||
|
||
These tools work nicely at first, but over time create some operational challenges: | ||
|
||
1. When a feature is no longer used, the database runtime must continue to support this to allow this migration to succeed. For example, if using Postgres and an extension is required and used, and then removed, the database migations will fail to run on a new database unless that extension is present, even though it's not needed in the end state. | ||
|
||
2. Performance starts to become slow on new environments. Eventually, in a rapid-iteration product, there can be hundreds of migrations. Replying these can be slow and any single failed migration will break the deployment. | ||
|
||
3. Database upgrades create incompatible migrations. After upgrading a database version, the syntax supported may change. This can leave older migrations unable to be applied against the current version of the databse. | ||
|
||
4. Concurrent changes can create conflicts or skipped migrations. These tools often employ a sequential (integer) counter or a timestamp. When multiple migrations are simultaneously prepared offline, these may have the same counter value or be commited in a different order than they were generated. This can cause the runtime to skip a migration. | ||
|
||
5. No dependency management between teams. | ||
|
||
#### Workarounds | ||
|
||
To help solve this, manual intervention is often taken to "rebase" the migrations. This is equivalent to retrieving a current schema from the database, deleting all migrations, and creating a single migration. This is a manual process that must be run occaisionally when using a sequential migration strategy. | ||
|
||
#### Benefits | ||
|
||
1. Ordering of columns is guaranteed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,3 @@ | ||
# Desired State Database Schema Management | ||
This document has moved to: | ||
|
||
There are many benefits to managing database schemas as code, including: | ||
1. Ability to adhere to a change management process | ||
2. Repeatable deployments to new environments | ||
... | ||
|
||
## Current Tools | ||
|
||
There are several commonly-used methods of managing database schemas employed today. | ||
|
||
1. Sequencial Migrations / Replay (Convergence) | ||
1. Declarative Schema Management | ||
|
||
### Sequential Migrations / Replay | ||
|
||
Tools such as db-migrate, Flyaway, goose and others fit into this category. These are immutable after deployment, stacked migrations that start from an empty database and consist of ordered create, alter and drop commands. | ||
|
||
#### Challenges | ||
|
||
These tools work nicely at first, but over time create some operational challenges: | ||
|
||
1. When a feature is no longer used, the database runtime must continue to support this to allow this migration to succeed. For example, if using Postgres and an extension is required and used, and then removed, the database migations will fail to run on a new database unless that extension is present, even though it's not needed in the end state. | ||
|
||
2. Performance starts to become slow on new environments. Eventually, in a rapid-iteration product, there can be hundreds of migrations. Replying these can be slow and any single failed migration will break the deployment. | ||
|
||
3. Database upgrades create incompatible migrations. After upgrading a database version, the syntax supported may change. This can leave older migrations unable to be applied against the current version of the databse. | ||
|
||
4. Concurrent changes can create conflicts or skipped migrations. These tools often employ a sequential (integer) counter or a timestamp. When multiple migrations are simultaneously prepared offline, these may have the same counter value or be commited in a different order than they were generated. This can cause the runtime to skip a migration. | ||
|
||
5. No dependency management between teams. | ||
|
||
#### Workarounds | ||
|
||
To help solve this, manual intervention is often taken to "rebase" the migrations. This is equivalent to retrieving a current schema from the database, deleting all migrations, and creating a single migration. This is a manual process that must be run occaisionally when using a sequential migration strategy. | ||
|
||
#### Benefits | ||
|
||
1. Ordering of columns is guaranteed. | ||
[https://github.com/schemahero/schemahero/blob/master/docs/design/desired-state-database-schema-management.md](https://github.com/schemahero/schemahero/blob/master/docs/design/desired-state-database-schema-management.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Schema Migrations and Data Migations | ||
|
||
There are two types of migratinos that have to be managed and deployed: | ||
|
||
1. Schema Migrations | ||
1. Data Migrations | ||
|
||
## Schema Migrations | ||
|
||
A Schema migration can be expressed in SQL syntax, and alters the structure of the database. These often are new tables, changing columns, altering indexed data and more. These are commonly written and can always be expressed in an idempotent syntax. Different database engines enforce various rules on how these can be applied. For example, MySQL will not allow a schema migration to be executed in a transaction, while Postgres will. Schema management is often unique to the database. | ||
|
||
## Data Migrations | ||
|
||
Less frequently, a developer must migrate some data to a new format in a database. This can involve calculating a new column and writing it, or creating new values in code and inserting them. Many traditional database management tools blend the tasks of schema migrations and data migrations into one tool. | ||
|
||
When looking at adding a data migration to a project, there is often a way to achieve the same result by implementing the update differently. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.