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.9.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

File details

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

File metadata

File hashes

Hashes for schema-change-risk-engine-0.0.9.tar.gz
Algorithm Hash digest
SHA256 e08540aa1de3e4f34e7dde0fd82f8d0fde3d4ff565432a01feb1700c03de7ba7
MD5 90d9c5ae3849b420e9b53ba7a294d92f
BLAKE2b-256 687021dd4285265f6abc2bf5205c759c678d16c431e9b6caa33b8af5cb581108

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for schema_change_risk_engine-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 1742f57a8d629b62bb3d024c43d0c74beff8d4ee9d8f0ceb367a2e0a958f117b
MD5 9d0fe61919753cbc414e7ed6b154259f
BLAKE2b-256 eaee951f1cc83353c2f025a90b099e7826541dcabf5cbcfa2a83d451134be9a4

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