Skip to main content

Common MySQL Schema Alter Issues Check Engine Package

Project description

SchemaChangeRiskEngine (SCRE):

A tool for assessing the risk of schema changes in a MySQL database when using tools like gh-ost or flywheel.

The problem

Based on Impact analysis of database schema changes and real world learning. It was found we should restrict riskier changes and patterns.

Such patterns include:

  • BLOB & TEXT column overuse and storage/memory waste
  • ENUM columns issues with casting during value parsing of a change
  • SET columns issues with casting during value parsing of a change
  • Foreign Key and Trigger usage preventing non-blocking and non-atomic changes
  • No Primary Key causing slow migration or table level locking verses row level locking
  • Renaming columns and tables leading toward application, data warehouse, and data lake sync issues

The solution

This tool addresses this by allowing you to pass any CREATE or ALTER statement, and it will return a boolean if it's safe.

Example

from schema_change_risk_engine import SchemaChangeRiskEngine as SCRE

engine = SCRE()
changeStatements = [
    """
        CREATE TABLE `test` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `name` varchar(255) NOT NULL,
        PRIMARY KEY (`id`)
        )
        ENGINE=InnoDB
        DEFAULT CHARSET=utf8mb4
        COLLATE=utf8mb4_0900_ai_ci
    """,
    "ALTER TABLE `test` ADD COLUMN `age` int(11) NOT NULL DEFAULT 0",
    "ALTER TABLE `test` RENAME COLUMN `age` to `years_old`",
    "ALTER TABLE `test` ADD COLUMN `gener` ENUM('M', 'F','T','NC') NOT NULL DEFAULT 'NC'",
    "ALTER TABLE `test` ADD COLUMN `hobbies` SET('S', 'R','T','NC') NOT NULL DEFAULT 'NC'",
    "ALTER TABLE `test` ADD COLUMN `bio` TEXT NOT NULL",
    "ALTER TABLE `test` ADD COLUMN `photo` BLOB NOT NULL",
    "ALTER TABLE `test` ADD COLUMN `order_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP",
    "ALTER TABLE `test` ADD TRIGGER `test_trigger` AFTER INSERT ON `test` FOR EACH ROW BEGIN INSERT INTO `test` (`name`) VALUES ('test'); END",
    "ALTER TABLE `test` ADD FOREIGN KEY (`id2`) REFERENCES `test` (`id`)",
    "ALTER TABLE `test` RENAME TO `test2`",
    "ALTER TABLE `test` RENAME TABLE `test2` TO `test`"
]

> for idx, change in enumerate(changeStatements):
    print("Statement %s: %s" % (idx + 1, engine.validate(change)))

Statement
1: (True, None)
Statement
2: (True, None)
Statement
3: (False, 'Renaming columns is not allowed')
Statement
4: (False, 'ENUM data type is not allowed')
Statement
5: (False, 'SET is not allowed')
Statement
6: (False, 'TEXT columns are not allowed')
Statement
7: (False, 'BLOB columns are not allowed')
Statement
8: (False, 'DATETIME data type is not allowed')
Statement
9: (False, 'Triggers are not allowed')
Statement
10: (False, 'Foreign keys are not allowed')
Statement
11: (False, 'Renaming tables is not allowed')
Statement
12: (False, 'Renaming tables is not allowed')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

schema-change-risk-engine-0.0.10.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file schema-change-risk-engine-0.0.10.tar.gz.

File metadata

File hashes

Hashes for schema-change-risk-engine-0.0.10.tar.gz
Algorithm Hash digest
SHA256 de06ff5aebd18ce00bd9a82309e2277c9085a18ff8de67db082f782a1e3c0197
MD5 1aab6d6b1f6d6062278cb0529c877d33
BLAKE2b-256 0b7bd0fb1f9d6ba44428eb5e780ee8bb00bb82bf306a7b71b3bfadda436a04f8

See more details on using hashes here.

File details

Details for the file schema_change_risk_engine-0.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for schema_change_risk_engine-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 ab5e082d9c228bd4e5b58118911c8a72a82dc38f5145f79d65390dc960b60a04
MD5 349089290fc372a9607e4c47d0756d3e
BLAKE2b-256 bcdeccc5999257760cbdc1d5fc8eb515d6c99ec4d87abdc3c2df2685e4221704

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page