Automatic MySQL Schema Management with Skeema
Evan Elias Percona Live, April 2017
Automatic MySQL Schema Management with Skeema Evan Elias Percona - - PowerPoint PPT Presentation
Automatic MySQL Schema Management with Skeema Evan Elias Percona Live, April 2017 What is Schema Management? Organize table schemas in a repo Execution of all DDL, on the correct MySQL instances, with the correct OSC flags Not
Evan Elias Percona Live, April 2017
correct OSC flags
management is a separate concept / higher layer
2
3
http://github.com/skeema/skeema
4
Skeema’s functionality combines/replaces several types of tools:
5
Schema dumper
Schema diff-er DDL / OSC executor
7
No need to ever create migrations or DDL by hand!
8
9
10
11
12
git diff skeema diff
13
arbitrary name)
dev DB on localhost”
14
environment, cluster, or schema
table size
15
16
[production] alter-wrapper="/usr/local/bin/pt-online-schema-change --execute --alter {CLAUSES} D={SCHEMA},t={TABLE},h={HOST},P={PORT},u={USER},p={PASSWORDX}" alter-wrapper-min-size=1g alter-algorithm=inplace alter-lock=none
17
[development] skip-alter-wrapper skip-alter-algorithm skip-alter-lock
“In everything but dev, apply extra safety checks to destructive DDL, but only for tables with at least one row. In dev, always allow destructive DDL without any extra safety checks.
18
safe-below-size=1 [dev] allow-unsafe
19
In /var/schemas/.skeema:
alter-wrapper="/usr/local/bin/pt-online-schema-change …”
In /var/schemas/some-cluster/some-schema/.skeema:
alter-wrapper="/usr/local/bin/pt-online-schema-change —extra-flag …”
20
In /var/schemas/special-cluster/.skeema:
connect-options=“innodb_lock_wait_timeout=60,sql_mode= ‘STRICT_ALL_TABLES,ALLOW_INVALID_DATES'”
22
Schema dumper
Schema diff-er DDL / OSC executor
Command: skeema init [environment]
containing a CREATE TABLE statement
port (at top level) or schema name (in each database subdir)
23
24
Same option-handling as the standard MySQL client! If ~/.my.cnf exists, automatically parsed for user and password. Default output dirname based on host/port; override with --dir
25
Example above assumes user and password obtained from ~/.my.cnf Port is non-standard due to use of Docker
26
27
28
Schema dumper
Schema diff-er DDL / OSC executor
Command: skeema pull [environment]
29
30
Schema dumper
Schema diff-er DDL / OSC executor
Command: skeema lint
CREATE TABLE
PK, etc
31
32
Original CREATE TABLE, with any arbitrary formatting
33
34
After reformatting
35
Another example: catching typos / invalid SQL
36
Command: skeema diff [environment]
37
Schema dumper
Schema diff-er DDL / OSC executor
generating DDL as output
the filesystem
38
39
Starting with the above table as an example
40
Let’s say we want to add a new col and index. Just edit the file.
41
skeema diff shows, but does not run, the corresponding DDL
complete!)
the full command-line
42
Command: skeema push [environment]
43
Schema dumper
Schema diff-er DDL / OSC executor
the DDL!
changes, then skeema push to execute them
show no remaining differences
44
45
46
48
DDL (if not using an external tool)
that are at least this size, in bytes
49
50
[production] alter-wrapper="/usr/local/bin/pt-online-schema-change --execute --alter {CLAUSES} D={SCHEMA},t={TABLE},h={HOST},P={PORT},u={USER},p={PASSWORDX}" alter-wrapper-min-size=1g alter-algorithm=inplace alter-lock=none
51
comma-separated list of them)
represent a cluster name instead
Command’s STDOUT will be parsed and interpreted as one or more hosts (or host:port) to use
52
The executed script should be capable of doing lookups (e.g. in ZooKeeper, etcd, or Consul) such as "return the master of pool foo" or "return all shard masters for sharded pool xyz"
53
host-wrapper=/some/script.sh /mysql/{ENVIRONMENT}/{HOST}
shard masters
54
56
[development] host=localhost socket=/path/to/mysql.sock allow-unsafe skip-alter-wrapper skip-alter-algorithm skip-alter-lock
# up-to-date
# to be applied to local dev
57
# changes to development
# to reflect those changes
58
59
(_skeema_tmp by default, but configurable)
61
62
engines, SSL, views, triggers, stored procs, fulltext, spatial
63