vitess.io/vitess@v0.16.2/go/vt/vtorc/db/generate_base.go (about)

     1  /*
     2     Copyright 2017 Shlomi Noach, GitHub Inc.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package db
    18  
    19  // vtorcBackend is a list of SQL statements required to build the vtorc backend
    20  var vtorcBackend = []string{
    21  	`
    22  DROP TABLE IF EXISTS database_instance
    23  `,
    24  	`
    25  CREATE TABLE database_instance (
    26  	hostname varchar(128) NOT NULL,
    27  	port smallint NOT NULL,
    28  	last_checked timestamp not null default (''),
    29  	last_seen timestamp NULL DEFAULT NULL,
    30  	server_id int NOT NULL,
    31  	version varchar(128) NOT NULL,
    32  	binlog_format varchar(16) NOT NULL,
    33  	log_bin tinyint NOT NULL,
    34  	log_replica_updates tinyint NOT NULL,
    35  	binary_log_file varchar(128) NOT NULL,
    36  	binary_log_pos bigint NOT NULL,
    37  	source_host varchar(128) NOT NULL,
    38  	source_port smallint NOT NULL,
    39  	replica_sql_running tinyint NOT NULL,
    40  	replica_io_running tinyint NOT NULL,
    41  	source_log_file varchar(128) NOT NULL,
    42  	read_source_log_pos bigint NOT NULL,
    43  	relay_source_log_file varchar(128) NOT NULL,
    44  	exec_source_log_pos bigint NOT NULL,
    45  	replication_lag_seconds bigint DEFAULT NULL,
    46  	replica_lag_seconds bigint DEFAULT NULL,
    47  	read_only TINYint not null default 0,
    48  	last_sql_error TEXT not null default '',
    49  	last_io_error TEXT not null default '',
    50  	oracle_gtid TINYint not null default 0,
    51  	mariadb_gtid TINYint not null default 0,
    52  	relay_log_file varchar(128) not null default '',
    53  	relay_log_pos bigint not null default 0,
    54  	pseudo_gtid TINYint not null default 0,
    55  	replication_depth TINYint not null default 0,
    56  	has_replication_filters TINYint not null default 0,
    57  	data_center varchar(32) not null default '',
    58  	physical_environment varchar(32) not null default '',
    59  	is_co_primary TINYint not null default 0,
    60  	sql_delay int not null default 0,
    61  	binlog_server TINYint not null default 0,
    62  	supports_oracle_gtid TINYint not null default 0,
    63  	executed_gtid_set text not null default '',
    64  	server_uuid varchar(64) not null default '',
    65  	last_attempted_check TIMESTAMP NOT NULL DEFAULT '1971-01-01 00:00:00',
    66  	gtid_purged text not null default '',
    67  	has_replication_credentials TINYint not null default 0,
    68  	allow_tls TINYint not null default 0,
    69  	semi_sync_enforced TINYint not null default 0,
    70  	instance_alias varchar(128) not null default '',
    71  	version_comment varchar(128) NOT NULL DEFAULT '',
    72  	major_version varchar(16) not null default '',
    73  	binlog_row_image varchar(16) not null default '',
    74  	last_discovery_latency bigint not null default 0,
    75  	semi_sync_primary_enabled TINYint not null default 0,
    76  	semi_sync_replica_enabled TINYint not null default 0,
    77  	gtid_mode varchar(32) not null default '',
    78  	last_check_partial_success tinyint not null default 0,
    79  	source_uuid varchar(64) not null default '',
    80  	gtid_errant text not null default '',
    81  	ancestry_uuid text not null default '',
    82  	replication_sql_thread_state tinyint signed not null default 0,
    83  	replication_io_thread_state tinyint signed not null default 0,
    84  	region varchar(32) not null default '',
    85  	semi_sync_primary_timeout int NOT NULL DEFAULT 0,
    86  	semi_sync_primary_wait_for_replica_count int NOT NULL DEFAULT 0,
    87  	semi_sync_primary_status TINYint NOT NULL DEFAULT 0,
    88  	semi_sync_replica_status TINYint NOT NULL DEFAULT 0,
    89  	semi_sync_primary_clients int NOT NULL DEFAULT 0,
    90  	replication_group_name VARCHAR(64) NOT NULL DEFAULT '',
    91  	replication_group_is_single_primary_mode TINYint NOT NULL DEFAULT 1,
    92  	replication_group_member_state VARCHAR(16) NOT NULL DEFAULT '',
    93  	replication_group_member_role VARCHAR(16) NOT NULL DEFAULT '',
    94  	replication_group_members text not null default '',
    95  	replication_group_primary_host varchar(128) NOT NULL DEFAULT '',
    96  	replication_group_primary_port smallint NOT NULL DEFAULT 0,
    97  	PRIMARY KEY (hostname,port)
    98  )`,
    99  	`
   100  CREATE INDEX last_checked_idx_database_instance ON database_instance(last_checked)
   101  	`,
   102  	`
   103  CREATE INDEX last_seen_idx_database_instance ON database_instance(last_seen)
   104  	`,
   105  	`
   106  DROP TABLE IF EXISTS database_instance_maintenance
   107  `,
   108  	`
   109  CREATE TABLE database_instance_maintenance (
   110  	database_instance_maintenance_id integer,
   111  	hostname varchar(128) NOT NULL,
   112  	port smallint NOT NULL,
   113  	maintenance_active tinyint(4) DEFAULT NULL,
   114  	begin_timestamp timestamp NULL DEFAULT NULL,
   115  	end_timestamp timestamp NULL DEFAULT NULL,
   116  	owner varchar(128) NOT NULL,
   117  	reason text NOT NULL,
   118  	processing_node_hostname varchar(128) not null default '',
   119  	processing_node_token varchar(128) not null default '',
   120  	explicitly_bounded TINYint not null default 0,
   121  	PRIMARY KEY (database_instance_maintenance_id)
   122  )`,
   123  	`
   124  CREATE UNIQUE INDEX maintenance_uidx_database_instance_maintenance ON database_instance_maintenance (maintenance_active, hostname, port)
   125  	`,
   126  	`
   127  DROP TABLE IF EXISTS database_instance_long_running_queries
   128  `,
   129  	`
   130  CREATE TABLE database_instance_long_running_queries (
   131  	hostname varchar(128) NOT NULL,
   132  	port smallint NOT NULL,
   133  	process_id bigint(20) NOT NULL,
   134  	process_started_at timestamp not null default (''),
   135  	process_user varchar(16) NOT NULL,
   136  	process_host varchar(128) NOT NULL,
   137  	process_db varchar(128) NOT NULL,
   138  	process_command varchar(16) NOT NULL,
   139  	process_time_seconds int(11) NOT NULL,
   140  	process_state varchar(128) NOT NULL,
   141  	process_info varchar(1024) NOT NULL,
   142  	PRIMARY KEY (hostname,port,process_id)
   143  )`,
   144  	`
   145  CREATE INDEX process_started_at_idx_database_instance_long_running_queries ON database_instance_long_running_queries (process_started_at)
   146  	`,
   147  	`
   148  DROP TABLE IF EXISTS audit
   149  `,
   150  	`
   151  CREATE TABLE audit (
   152  	audit_id integer,
   153  	audit_timestamp timestamp not null default (''),
   154  	audit_type varchar(128) NOT NULL,
   155  	hostname varchar(128) NOT NULL DEFAULT '',
   156  	port smallint NOT NULL,
   157  	message text NOT NULL,
   158  	keyspace varchar(128) NOT NULL,
   159  	shard varchar(128) NOT NULL,
   160  	PRIMARY KEY (audit_id)
   161  )`,
   162  	`
   163  CREATE INDEX audit_timestamp_idx_audit ON audit (audit_timestamp)
   164  	`,
   165  	`
   166  CREATE INDEX host_port_idx_audit ON audit (hostname, port, audit_timestamp)
   167  	`,
   168  	`
   169  DROP TABLE IF EXISTS host_agent
   170  `,
   171  	`
   172  CREATE TABLE host_agent (
   173  	hostname varchar(128) NOT NULL,
   174  	port smallint NOT NULL,
   175  	token varchar(128) NOT NULL,
   176  	last_submitted timestamp not null default (''),
   177  	last_checked timestamp NULL DEFAULT NULL,
   178  	last_seen timestamp NULL DEFAULT NULL,
   179  	mysql_port smallint DEFAULT NULL,
   180  	count_mysql_snapshots smallint NOT NULL,
   181  	PRIMARY KEY (hostname)
   182  )`,
   183  	`
   184  CREATE INDEX token_idx_host_agent ON host_agent (token)
   185  	`,
   186  	`
   187  CREATE INDEX last_submitted_idx_host_agent ON host_agent (last_submitted)
   188  	`,
   189  	`
   190  CREATE INDEX last_checked_idx_host_agent ON host_agent (last_checked)
   191  	`,
   192  	`
   193  CREATE INDEX last_seen_idx_host_agent ON host_agent (last_seen)
   194  	`,
   195  	`
   196  DROP TABLE IF EXISTS agent_seed
   197  `,
   198  	`
   199  CREATE TABLE agent_seed (
   200  	agent_seed_id integer,
   201  	target_hostname varchar(128) NOT NULL,
   202  	source_hostname varchar(128) NOT NULL,
   203  	start_timestamp timestamp not null default (''),
   204  	end_timestamp timestamp NOT NULL DEFAULT '1971-01-01 00:00:00',
   205  	is_complete tinyint NOT NULL DEFAULT '0',
   206  	is_successful tinyint NOT NULL DEFAULT '0',
   207  	PRIMARY KEY (agent_seed_id)
   208  )`,
   209  	`
   210  CREATE INDEX target_hostname_idx_agent_seed ON agent_seed (target_hostname,is_complete)
   211  	`,
   212  	`
   213  CREATE INDEX source_hostname_idx_agent_seed ON agent_seed (source_hostname,is_complete)
   214  	`,
   215  	`
   216  CREATE INDEX start_timestamp_idx_agent_seed ON agent_seed (start_timestamp)
   217  	`,
   218  	`
   219  CREATE INDEX is_complete_idx_agent_seed ON agent_seed (is_complete,start_timestamp)
   220  	`,
   221  	`
   222  CREATE INDEX is_successful_idx_agent_seed ON agent_seed (is_successful, start_timestamp)
   223  	`,
   224  	`
   225  DROP TABLE IF EXISTS agent_seed_state
   226  `,
   227  	`
   228  CREATE TABLE agent_seed_state (
   229  	agent_seed_state_id integer,
   230  	agent_seed_id int NOT NULL,
   231  	state_timestamp timestamp not null default (''),
   232  	state_action varchar(127) NOT NULL,
   233  	error_message varchar(255) NOT NULL,
   234  	PRIMARY KEY (agent_seed_state_id)
   235  )`,
   236  	`
   237  CREATE INDEX agent_seed_idx_agent_seed_state ON agent_seed_state (agent_seed_id, state_timestamp)
   238  	`,
   239  	`
   240  DROP TABLE IF EXISTS hostname_resolve
   241  `,
   242  	`
   243  CREATE TABLE hostname_resolve (
   244  	hostname varchar(128) NOT NULL,
   245  	resolved_hostname varchar(128) NOT NULL,
   246  	resolved_timestamp timestamp not null default (''),
   247  	PRIMARY KEY (hostname)
   248  )`,
   249  	`
   250  CREATE INDEX resolved_timestamp_idx_hostname_resolve ON hostname_resolve (resolved_timestamp)
   251  	`,
   252  	`
   253  DROP TABLE IF EXISTS active_node
   254  `,
   255  	`
   256  CREATE TABLE active_node (
   257  	anchor tinyint NOT NULL,
   258  	hostname varchar(128) NOT NULL,
   259  	token varchar(128) NOT NULL,
   260  	last_seen_active timestamp not null default (''),
   261  	first_seen_active timestamp NOT NULL DEFAULT '1971-01-01 00:00:00',
   262  	PRIMARY KEY (anchor)
   263  )`,
   264  	`
   265  DROP TABLE IF EXISTS node_health
   266  `,
   267  	`
   268  CREATE TABLE node_health (
   269  	hostname varchar(128) NOT NULL,
   270  	token varchar(128) NOT NULL,
   271  	last_seen_active timestamp not null default (''),
   272  	extra_info varchar(128) not null default '',
   273  	command varchar(128) not null default '',
   274  	app_version varchar(64) NOT NULL DEFAULT "",
   275  	first_seen_active timestamp NOT NULL DEFAULT '1971-01-01 00:00:00',
   276  	db_backend varchar(255) NOT NULL DEFAULT "",
   277  	incrementing_indicator bigint not null default 0,
   278  	PRIMARY KEY (hostname, token)
   279  )`,
   280  	`
   281  DROP TABLE IF EXISTS topology_recovery
   282  `,
   283  	`
   284  CREATE TABLE topology_recovery (
   285  	recovery_id integer,
   286  	hostname varchar(128) NOT NULL,
   287  	port smallint NOT NULL,
   288  	in_active_period tinyint NOT NULL DEFAULT 0,
   289  	start_active_period timestamp not null default (''),
   290  	end_active_period_unixtime int,
   291  	end_recovery timestamp NULL DEFAULT NULL,
   292  	processing_node_hostname varchar(128) NOT NULL,
   293  	processcing_node_token varchar(128) NOT NULL,
   294  	successor_hostname varchar(128) DEFAULT NULL,
   295  	successor_port smallint DEFAULT NULL,
   296  	analysis varchar(128) not null default '',
   297  	keyspace varchar(128) NOT NULL,
   298  	shard varchar(128) NOT NULL,
   299  	count_affected_replicas int not null default 0,
   300  	is_successful TINYint NOT NULL DEFAULT 0,
   301  	acknowledged TINYint NOT NULL DEFAULT 0,
   302  	acknowledged_by varchar(128) not null default '',
   303  	acknowledge_comment text not null default '',
   304  	participating_instances text not null default '',
   305  	lost_replicas text not null default '',
   306  	all_errors text not null default '',
   307  	acknowledged_at TIMESTAMP NULL,
   308  	last_detection_id bigint not null default 0,
   309  	successor_alias varchar(128) DEFAULT NULL,
   310  	uid varchar(128) not null default '',
   311  	PRIMARY KEY (recovery_id)
   312  )`,
   313  	`
   314  CREATE INDEX in_active_start_period_idx_topology_recovery ON topology_recovery (in_active_period, start_active_period)
   315  	`,
   316  	`
   317  CREATE INDEX start_active_period_idx_topology_recovery ON topology_recovery (start_active_period)
   318  	`,
   319  	`
   320  CREATE UNIQUE INDEX hostname_port_active_period_uidx_topology_recovery ON topology_recovery (hostname, port, in_active_period, end_active_period_unixtime)
   321  	`,
   322  	`
   323  DROP TABLE IF EXISTS hostname_unresolve
   324  `,
   325  	`
   326  CREATE TABLE hostname_unresolve (
   327  	hostname varchar(128) NOT NULL,
   328  	unresolved_hostname varchar(128) NOT NULL,
   329  	last_registered timestamp not null default (''),
   330  	PRIMARY KEY (hostname)
   331  )`,
   332  	`
   333  CREATE INDEX unresolved_hostname_idx_hostname_unresolve ON hostname_unresolve (unresolved_hostname)
   334  	`,
   335  	`
   336  DROP TABLE IF EXISTS database_instance_topology_history
   337  `,
   338  	`
   339  CREATE TABLE database_instance_topology_history (
   340  	snapshot_unix_timestamp int NOT NULL,
   341  	hostname varchar(128) NOT NULL,
   342  	port smallint NOT NULL,
   343  	source_host varchar(128) NOT NULL,
   344  	source_port smallint NOT NULL,
   345  	keyspace varchar(128) NOT NULL,
   346  	shard varchar(128) NOT NULL,
   347  	version varchar(128) not null default '',
   348  	PRIMARY KEY (snapshot_unix_timestamp, hostname, port)
   349  )`,
   350  	`
   351  CREATE INDEX keyspace_shard_idx_database_instance_topology_history ON database_instance_topology_history (snapshot_unix_timestamp, keyspace, shard)
   352  	`,
   353  	`
   354  DROP TABLE IF EXISTS candidate_database_instance
   355  `,
   356  	`
   357  CREATE TABLE candidate_database_instance (
   358  	hostname varchar(128) NOT NULL,
   359  	port smallint NOT NULL,
   360  	last_suggested timestamp not null default (''),
   361  	priority TINYINT SIGNED NOT NULL DEFAULT 1,
   362  	promotion_rule text check(promotion_rule in ('must', 'prefer', 'neutral', 'prefer_not', 'must_not')) NOT NULL DEFAULT 'neutral',
   363  	PRIMARY KEY (hostname, port)
   364  )`,
   365  	`
   366  CREATE INDEX last_suggested_idx_candidate_database_instance ON candidate_database_instance (last_suggested)
   367  	`,
   368  	`
   369  DROP TABLE IF EXISTS database_instance_downtime
   370  `,
   371  	`
   372  CREATE TABLE database_instance_downtime (
   373  	hostname varchar(128) NOT NULL,
   374  	port smallint NOT NULL,
   375  	downtime_active tinyint(4) DEFAULT NULL,
   376  	begin_timestamp timestamp default (''),
   377  	end_timestamp timestamp NULL DEFAULT NULL,
   378  	owner varchar(128) NOT NULL,
   379  	reason text NOT NULL,
   380  	PRIMARY KEY (hostname, port)
   381  )`,
   382  	`
   383  DROP TABLE IF EXISTS topology_failure_detection
   384  `,
   385  	`
   386  CREATE TABLE topology_failure_detection (
   387  	detection_id integer,
   388  	hostname varchar(128) NOT NULL,
   389  	port smallint NOT NULL,
   390  	in_active_period tinyint NOT NULL DEFAULT '0',
   391  	start_active_period timestamp not null default (''),
   392  	end_active_period_unixtime int NOT NULL,
   393  	processing_node_hostname varchar(128) NOT NULL,
   394  	processcing_node_token varchar(128) NOT NULL,
   395  	analysis varchar(128) NOT NULL,
   396  	keyspace varchar(128) NOT NULL,
   397  	shard varchar(128) NOT NULL,
   398  	count_affected_replicas int NOT NULL,
   399  	is_actionable tinyint not null default 0,
   400  	PRIMARY KEY (detection_id)
   401  )`,
   402  	`
   403  CREATE INDEX in_active_start_period_idx_topology_failure_detection ON topology_failure_detection (in_active_period, start_active_period)
   404  	`,
   405  	`
   406  DROP TABLE IF EXISTS hostname_resolve_history
   407  `,
   408  	`
   409  CREATE TABLE hostname_resolve_history (
   410  	resolved_hostname varchar(128) NOT NULL,
   411  	hostname varchar(128) NOT NULL,
   412  	resolved_timestamp timestamp not null default (''),
   413  	PRIMARY KEY (resolved_hostname)
   414  )`,
   415  	`
   416  CREATE INDEX hostname_idx_hostname_resolve_history ON hostname_resolve_history (hostname)
   417  	`,
   418  	`
   419  CREATE INDEX resolved_timestamp_idx_hostname_resolve_history ON hostname_resolve_history (resolved_timestamp)
   420  	`,
   421  	`
   422  DROP TABLE IF EXISTS hostname_unresolve_history
   423  `,
   424  	`
   425  CREATE TABLE hostname_unresolve_history (
   426  	unresolved_hostname varchar(128) NOT NULL,
   427  	hostname varchar(128) NOT NULL,
   428  	last_registered timestamp not null default (''),
   429  	PRIMARY KEY (unresolved_hostname)
   430  )`,
   431  	`
   432  CREATE INDEX hostname_idx_hostname_unresolve_history ON hostname_unresolve_history (hostname)
   433  	`,
   434  	`
   435  CREATE INDEX last_registered_idx_hostname_unresolve_history ON hostname_unresolve_history (last_registered)
   436  	`,
   437  	`
   438  DROP TABLE IF EXISTS primary_position_equivalence
   439  `,
   440  	`
   441  CREATE TABLE primary_position_equivalence (
   442  	equivalence_id integer,
   443  	primary1_hostname varchar(128) NOT NULL,
   444  	primary1_port smallint NOT NULL,
   445  	primary1_binary_log_file varchar(128) NOT NULL,
   446  	primary1_binary_log_pos bigint NOT NULL,
   447  	primary2_hostname varchar(128) NOT NULL,
   448  	primary2_port smallint NOT NULL,
   449  	primary2_binary_log_file varchar(128) NOT NULL,
   450  	primary2_binary_log_pos bigint NOT NULL,
   451  	last_suggested timestamp not null default (''),
   452  	PRIMARY KEY (equivalence_id)
   453  )`,
   454  	`
   455  CREATE UNIQUE INDEX equivalence_uidx_primary_position_equivalence ON primary_position_equivalence (primary1_hostname, primary1_port, primary1_binary_log_file, primary1_binary_log_pos, primary2_hostname, primary2_port)
   456  	`,
   457  	`
   458  CREATE INDEX primary2_idx_primary_position_equivalence ON primary_position_equivalence (primary2_hostname, primary2_port, primary2_binary_log_file, primary2_binary_log_pos)
   459  	`,
   460  	`
   461  CREATE INDEX last_suggested_idx_primary_position_equivalence ON primary_position_equivalence (last_suggested)
   462  	`,
   463  	`
   464  DROP TABLE IF EXISTS async_request
   465  `,
   466  	`
   467  CREATE TABLE async_request (
   468  	request_id integer,
   469  	command varchar(128) not null,
   470  	hostname varchar(128) NOT NULL,
   471  	port smallint NOT NULL,
   472  	destination_hostname varchar(128) NOT NULL,
   473  	destination_port smallint NOT NULL,
   474  	pattern text NOT NULL,
   475  	gtid_hint varchar(32) not null,
   476  	begin_timestamp timestamp NULL DEFAULT NULL,
   477  	end_timestamp timestamp NULL DEFAULT NULL,
   478  	story text NOT NULL,
   479  	PRIMARY KEY (request_id)
   480  )`,
   481  	`
   482  CREATE INDEX begin_timestamp_idx_async_request ON async_request (begin_timestamp)
   483  	`,
   484  	`
   485  CREATE INDEX end_timestamp_idx_async_request ON async_request (end_timestamp)
   486  	`,
   487  	`
   488  DROP TABLE IF EXISTS blocked_topology_recovery
   489  `,
   490  	`
   491  CREATE TABLE blocked_topology_recovery (
   492  	hostname varchar(128) NOT NULL,
   493  	port smallint NOT NULL,
   494  	keyspace varchar(128) NOT NULL,
   495  	shard varchar(128) NOT NULL,
   496  	analysis varchar(128) NOT NULL,
   497  	last_blocked_timestamp timestamp not null default (''),
   498  	blocking_recovery_id bigint,
   499  	PRIMARY KEY (hostname, port)
   500  )`,
   501  	`
   502  CREATE INDEX keyspace_shard_blocked_idx_blocked_topology_recovery ON blocked_topology_recovery (keyspace, shard, last_blocked_timestamp)
   503  	`,
   504  	`
   505  DROP TABLE IF EXISTS database_instance_last_analysis
   506  `,
   507  	`
   508  CREATE TABLE database_instance_last_analysis (
   509  	hostname varchar(128) NOT NULL,
   510  	port smallint NOT NULL,
   511  	analysis_timestamp timestamp not null default (''),
   512  	analysis varchar(128) NOT NULL,
   513  	PRIMARY KEY (hostname, port)
   514  )`,
   515  	`
   516  CREATE INDEX analysis_timestamp_idx_database_instance_last_analysis ON database_instance_last_analysis (analysis_timestamp)
   517  	`,
   518  	`
   519  DROP TABLE IF EXISTS database_instance_analysis_changelog
   520  `,
   521  	`
   522  CREATE TABLE database_instance_analysis_changelog (
   523  	changelog_id integer,
   524  	hostname varchar(128) NOT NULL,
   525  	port smallint NOT NULL,
   526  	analysis_timestamp timestamp not null default (''),
   527  	analysis varchar(128) NOT NULL,
   528  	PRIMARY KEY (changelog_id)
   529  )`,
   530  	`
   531  CREATE INDEX analysis_timestamp_idx_database_instance_analysis_changelog ON database_instance_analysis_changelog (analysis_timestamp)
   532  	`,
   533  	`
   534  DROP TABLE IF EXISTS node_health_history
   535  `,
   536  	`
   537  CREATE TABLE node_health_history (
   538  	history_id integer,
   539  	hostname varchar(128) NOT NULL,
   540  	token varchar(128) NOT NULL,
   541  	first_seen_active timestamp NOT NULL,
   542  	extra_info varchar(128) NOT NULL,
   543  	command varchar(128) not null default '',
   544  	app_version varchar(64) NOT NULL DEFAULT "",
   545  	PRIMARY KEY (history_id)
   546  )`,
   547  	`
   548  CREATE INDEX first_seen_active_idx_node_health_history ON node_health_history (first_seen_active)
   549  	`,
   550  	`
   551  CREATE UNIQUE INDEX hostname_token_idx_node_health_history ON node_health_history (hostname, token)
   552  	`,
   553  	`
   554  DROP TABLE IF EXISTS database_instance_coordinates_history
   555  `,
   556  	`
   557  CREATE TABLE database_instance_coordinates_history (
   558  	history_id integer,
   559  	hostname varchar(128) NOT NULL,
   560  	port smallint NOT NULL,
   561  	recorded_timestamp timestamp not null default (''),
   562  	binary_log_file varchar(128) NOT NULL,
   563  	binary_log_pos bigint NOT NULL,
   564  	relay_log_file varchar(128) NOT NULL,
   565  	relay_log_pos bigint NOT NULL,
   566  	last_seen timestamp NOT NULL DEFAULT '1971-01-01 00:00:00',
   567  	PRIMARY KEY (history_id)
   568  )`,
   569  	`
   570  CREATE INDEX hostname_port_recorded_idx_database_instance_coordinates_history ON database_instance_coordinates_history (hostname, port, recorded_timestamp)
   571  	`,
   572  	`
   573  CREATE INDEX recorded_timestmp_idx_database_instance_coordinates_history ON database_instance_coordinates_history (recorded_timestamp)
   574  	`,
   575  	`
   576  DROP TABLE IF EXISTS database_instance_binlog_files_history
   577  `,
   578  	`
   579  CREATE TABLE database_instance_binlog_files_history (
   580  	history_id integer,
   581  	hostname varchar(128) NOT NULL,
   582  	port smallint NOT NULL,
   583  	binary_log_file varchar(128) NOT NULL,
   584  	binary_log_pos bigint NOT NULL,
   585  	first_seen timestamp not null default (''),
   586  	last_seen timestamp NOT NULL DEFAULT '1971-01-01 00:00:00',
   587  	PRIMARY KEY (history_id)
   588  )`,
   589  	`
   590  CREATE UNIQUE INDEX hostname_port_file_idx_database_instance_binlog_files_history ON database_instance_binlog_files_history (hostname, port, binary_log_file)
   591  	`,
   592  	`
   593  CREATE INDEX last_seen_idx_database_instance_binlog_files_history ON database_instance_binlog_files_history (last_seen)
   594  	`,
   595  	`
   596  DROP TABLE IF EXISTS database_instance_recent_relaylog_history
   597  `,
   598  	`
   599  CREATE TABLE database_instance_recent_relaylog_history (
   600  	hostname varchar(128) NOT NULL,
   601  	port smallint NOT NULL,
   602  	current_relay_log_file varchar(128) NOT NULL,
   603  	current_relay_log_pos bigint NOT NULL,
   604  	current_seen timestamp NOT NULL DEFAULT '1971-01-01 00:00:00',
   605  	prev_relay_log_file varchar(128) NOT NULL,
   606  	prev_relay_log_pos bigint NOT NULL,
   607  	prev_seen timestamp NOT NULL DEFAULT '1971-01-01 00:00:00',
   608  	PRIMARY KEY (hostname, port)
   609  )`,
   610  	`
   611  CREATE INDEX current_seen_idx_database_instance_recent_relaylog_history ON database_instance_recent_relaylog_history (current_seen)
   612  	`,
   613  	`
   614  DROP TABLE IF EXISTS vtorc_metadata
   615  `,
   616  	`
   617  CREATE TABLE vtorc_metadata (
   618  	anchor tinyint NOT NULL,
   619  	last_deployed_version varchar(128) NOT NULL,
   620  	last_deployed_timestamp timestamp NOT NULL,
   621  	PRIMARY KEY (anchor)
   622  )`,
   623  	`
   624  DROP TABLE IF EXISTS vtorc_db_deployments
   625  `,
   626  	`
   627  CREATE TABLE vtorc_db_deployments (
   628  	deployed_version varchar(128) NOT NULL,
   629  	deployed_timestamp timestamp NOT NULL,
   630  	PRIMARY KEY (deployed_version)
   631  )`,
   632  	`
   633  DROP TABLE IF EXISTS global_recovery_disable
   634  `,
   635  	`
   636  CREATE TABLE global_recovery_disable (
   637  	disable_recovery tinyint NOT NULL ,
   638  	PRIMARY KEY (disable_recovery)
   639  )`,
   640  	`
   641  DROP TABLE IF EXISTS topology_recovery_steps
   642  `,
   643  	`
   644  CREATE TABLE topology_recovery_steps (
   645  	recovery_step_id integer,
   646  	recovery_uid varchar(128) NOT NULL,
   647  	audit_at timestamp not null default (''),
   648  	message text NOT NULL,
   649  	PRIMARY KEY (recovery_step_id)
   650  )`,
   651  	`
   652  DROP TABLE IF EXISTS raft_store
   653  `,
   654  	`
   655  CREATE TABLE raft_store (
   656  	store_id integer,
   657  	store_key varbinary(512) not null,
   658  	store_value blob not null,
   659  	PRIMARY KEY (store_id)
   660  )`,
   661  	`
   662  CREATE INDEX store_key_idx_raft_store ON raft_store (store_key)
   663  	`,
   664  	`
   665  DROP TABLE IF EXISTS raft_log
   666  `,
   667  	`
   668  CREATE TABLE raft_log (
   669  	log_index integer,
   670  	term bigint not null,
   671  	log_type int not null,
   672  	data blob not null,
   673  	PRIMARY KEY (log_index)
   674  )`,
   675  	`
   676  DROP TABLE IF EXISTS raft_snapshot
   677  `,
   678  	`
   679  CREATE TABLE raft_snapshot (
   680  	snapshot_id integer,
   681  	snapshot_name varchar(128) NOT NULL,
   682  	snapshot_meta varchar(4096) NOT NULL,
   683  	created_at timestamp not null default (''),
   684  	PRIMARY KEY (snapshot_id)
   685  )`,
   686  	`
   687  CREATE UNIQUE INDEX snapshot_name_uidx_raft_snapshot ON raft_snapshot (snapshot_name)
   688  	`,
   689  	`
   690  DROP TABLE IF EXISTS database_instance_peer_analysis
   691  `,
   692  	`
   693  CREATE TABLE database_instance_peer_analysis (
   694  	peer varchar(128) NOT NULL,
   695  	hostname varchar(128) NOT NULL,
   696  	port smallint NOT NULL,
   697  	analysis_timestamp timestamp not null default (''),
   698  	analysis varchar(128) NOT NULL,
   699  	PRIMARY KEY (peer, hostname, port)
   700  )`,
   701  	`
   702  DROP TABLE IF EXISTS database_instance_tls
   703  `,
   704  	`
   705  CREATE TABLE database_instance_tls (
   706  	hostname varchar(128) NOT NULL,
   707  	port smallint NOT NULL,
   708  	required tinyint NOT NULL DEFAULT 0,
   709  	PRIMARY KEY (hostname,port)
   710  )`,
   711  	`
   712  DROP TABLE IF EXISTS hostname_ips
   713  `,
   714  	`
   715  CREATE TABLE hostname_ips (
   716  	hostname varchar(128) NOT NULL,
   717  	ipv4 varchar(128) NOT NULL,
   718  	ipv6 varchar(128) NOT NULL,
   719  	last_updated timestamp not null default (''),
   720  	PRIMARY KEY (hostname)
   721  )`,
   722  	`
   723  DROP TABLE IF EXISTS database_instance_tags
   724  `,
   725  	`
   726  CREATE TABLE database_instance_tags (
   727  	hostname varchar(128) NOT NULL,
   728  	port smallint NOT NULL,
   729  	tag_name varchar(128) NOT NULL,
   730  	tag_value varchar(128) NOT NULL,
   731  	last_updated timestamp not null default (''),
   732  	PRIMARY KEY (hostname, port, tag_name)
   733  )`,
   734  	`
   735  CREATE INDEX tag_name_idx_database_instance_tags ON database_instance_tags (tag_name)
   736  	`,
   737  	`
   738  DROP TABLE IF EXISTS database_instance_stale_binlog_coordinates
   739  `,
   740  	`
   741  CREATE TABLE database_instance_stale_binlog_coordinates (
   742  	hostname varchar(128) NOT NULL,
   743  	port smallint NOT NULL,
   744  	binary_log_file varchar(128) NOT NULL,
   745  	binary_log_pos bigint NOT NULL,
   746  	first_seen timestamp not null default (''),
   747  	PRIMARY KEY (hostname, port)
   748  )`,
   749  	`
   750  CREATE INDEX first_seen_idx_database_instance_stale_binlog_coordinates ON database_instance_stale_binlog_coordinates (first_seen)
   751  	`,
   752  	`
   753  DROP TABLE IF EXISTS vitess_tablet
   754  `,
   755  	`
   756  CREATE TABLE vitess_tablet (
   757  	alias varchar(256) NOT NULL,
   758  	hostname varchar(128) NOT NULL,
   759  	port smallint NOT NULL,
   760  	keyspace varchar(128) NOT NULL,
   761  	shard varchar(128) NOT NULL,
   762  	cell varchar(128) NOT NULL,
   763  	tablet_type smallint(5) NOT NULL,
   764  	primary_timestamp timestamp NOT NULL,
   765  	info varchar(512) NOT NULL,
   766  	UNIQUE (alias),
   767  	PRIMARY KEY (hostname, port)
   768  )`,
   769  	`
   770  CREATE INDEX cell_idx_vitess_tablet ON vitess_tablet (cell)
   771  	`,
   772  	`
   773  CREATE INDEX ks_idx_vitess_tablet ON vitess_tablet (keyspace, shard)
   774  	`,
   775  	`
   776  DROP TABLE IF EXISTS vitess_keyspace
   777  `,
   778  	`
   779  CREATE TABLE vitess_keyspace (
   780  	keyspace varchar(128) NOT NULL,
   781  	keyspace_type smallint(5) NOT NULL,
   782  	durability_policy varchar(512) NOT NULL,
   783  	PRIMARY KEY (keyspace)
   784  )`,
   785  	`
   786  CREATE INDEX source_host_port_idx_database_instance_database_instance on database_instance (source_host, source_port)
   787  	`,
   788  	`
   789  CREATE INDEX active_timestamp_idx_database_instance_maintenance on database_instance_maintenance (maintenance_active, begin_timestamp)
   790  	`,
   791  	`
   792  CREATE INDEX active_end_timestamp_idx_database_instance_maintenance on database_instance_maintenance (maintenance_active, end_timestamp)
   793  	`,
   794  	`
   795  CREATE INDEX last_registered_idx_hostname_unresolve on hostname_unresolve (last_registered)
   796  	`,
   797  	`
   798  CREATE INDEX keyspace_shard_in_active_idx_topology_recovery on topology_recovery (keyspace, shard, in_active_period)
   799  	`,
   800  	`
   801  CREATE INDEX end_recovery_idx_topology_recovery on topology_recovery (end_recovery)
   802  	`,
   803  	`
   804  CREATE INDEX acknowledged_idx_topology_recovery on topology_recovery (acknowledged, acknowledged_at)
   805  	`,
   806  	`
   807  CREATE INDEX last_blocked_idx_blocked_topology_recovery on blocked_topology_recovery (last_blocked_timestamp)
   808  	`,
   809  	`
   810  CREATE INDEX instance_timestamp_idx_database_instance_analysis_changelog on database_instance_analysis_changelog (hostname, port, analysis_timestamp)
   811  	`,
   812  	`
   813  CREATE INDEX last_detection_idx_topology_recovery on topology_recovery (last_detection_id)
   814  	`,
   815  	`
   816  CREATE INDEX last_seen_active_idx_node_health on node_health (last_seen_active)
   817  	`,
   818  	`
   819  CREATE INDEX uid_idx_topology_recovery ON topology_recovery(uid)
   820  	`,
   821  	`
   822  CREATE INDEX recovery_uid_idx_topology_recovery_steps ON topology_recovery_steps(recovery_uid)
   823  	`,
   824  	`
   825  CREATE INDEX end_timestamp_idx_database_instance_downtime ON database_instance_downtime(end_timestamp)
   826  	`,
   827  	`
   828  CREATE UNIQUE INDEX host_port_active_recoverable_uidx_topology_failure_detection ON topology_failure_detection (hostname, port, in_active_period, end_active_period_unixtime, is_actionable)
   829  	`,
   830  }