mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-10 02:45:20 +00:00
[3567] Applied updated patch by Adam
- upgrade 2.0 to 3.0 script added - added unit-tests - dhcpdb_create.mysql script now uses the same database
This commit is contained in:
@@ -166,121 +166,88 @@ UPDATE schema_version SET version="2", minor="0";
|
||||
# This line starts database upgrade to version 3.0.
|
||||
# Upgrade extending MySQL schema with the ability to store hosts.
|
||||
|
||||
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
|
||||
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
|
||||
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS `kea_host_reservation` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
|
||||
USE `kea_host_reservation` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS hosts (
|
||||
host_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
dhcp_identifier VARBINARY(128) NOT NULL,
|
||||
dhcp_identifier_type TINYINT NOT NULL,
|
||||
dhcp4_subnet_id INT UNSIGNED NULL,
|
||||
dhcp6_subnet_id INT UNSIGNED NULL,
|
||||
ipv4_address INT UNSIGNED NULL,
|
||||
hostname VARCHAR(255) NULL,
|
||||
dhcp4_client_classes VARCHAR(255) NULL,
|
||||
dhcp6_client_classes VARCHAR(255) NULL,
|
||||
PRIMARY KEY (host_id),
|
||||
INDEX key_dhcp4_identifier_subnet_id (dhcp_identifier ASC , dhcp_identifier_type ASC),
|
||||
INDEX key_dhcp6_identifier_subnet_id (dhcp_identifier ASC , dhcp_identifier_type ASC , dhcp6_subnet_id ASC)
|
||||
) ENGINE=INNODB;
|
||||
-- -----------------------------------------------------
|
||||
-- Table `kea_host_reservation`.`hosts`
|
||||
-- Table `ipv6_reservations`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `kea_host_reservation`.`hosts` (
|
||||
`host_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
|
||||
`dhcp_identifier` VARBINARY(128) NOT NULL ,
|
||||
`dhcp_identifier_type` TINYINT NOT NULL ,
|
||||
`dhcp4_subnet_id` INT UNSIGNED NULL ,
|
||||
`dhcp6_subnet_id` INT UNSIGNED NULL ,
|
||||
`ipv4_address` INT UNSIGNED NULL ,
|
||||
`hostname` VARCHAR(255) NULL ,
|
||||
`dhcp4_cllient_classes` VARCHAR(255) NULL ,
|
||||
`dhcp6_client_classes` VARCHAR(255) NULL ,
|
||||
PRIMARY KEY (`host_id`) ,
|
||||
INDEX `key_dhcp4_identifier_subnet_id` (`dhcp_identifier` ASC, `dhcp_identifier_type` ASC) ,
|
||||
INDEX `key_dhcp6_identifier_subnet_id` (`dhcp_identifier` ASC, `dhcp_identifier_type` ASC, `dhcp6_subnet_id` ASC) )
|
||||
ENGINE = InnoDB;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ipv6_reservations (
|
||||
reservation_id INT NOT NULL AUTO_INCREMENT,
|
||||
address VARCHAR(39) NOT NULL,
|
||||
prefix_len TINYINT(3) UNSIGNED NOT NULL DEFAULT 128,
|
||||
type TINYINT(4) UNSIGNED NOT NULL DEFAULT 0,
|
||||
dhcp6_iaid INT UNSIGNED NULL,
|
||||
host_id INT UNSIGNED NOT NULL,
|
||||
PRIMARY KEY (reservation_id),
|
||||
INDEX fk_ipv6_reservations_host_idx (host_id ASC),
|
||||
CONSTRAINT fk_ipv6_reservations_Host FOREIGN KEY (host_id)
|
||||
REFERENCES hosts (host_id)
|
||||
ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
) ENGINE=INNODB;
|
||||
-- -----------------------------------------------------
|
||||
-- Table `kea_host_reservation`.`ipv6_reservations`
|
||||
-- Table `dhcp4_options`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `kea_host_reservation`.`ipv6_reservations` (
|
||||
`reservation_id` INT NOT NULL AUTO_INCREMENT ,
|
||||
`address` VARCHAR(39) NOT NULL ,
|
||||
`prefix_len` TINYINT(3) UNSIGNED NOT NULL DEFAULT 128 ,
|
||||
`type` TINYINT(4) UNSIGNED NOT NULL DEFAULT 0 ,
|
||||
`dhcp6_iaid` INT UNSIGNED NULL ,
|
||||
`host_id` INT UNSIGNED NOT NULL ,
|
||||
PRIMARY KEY (`reservation_id`) ,
|
||||
INDEX `fk_ipv6_reservations_host_idx` (`host_id` ASC) ,
|
||||
CONSTRAINT `fk_ipv6_reservations_Host`
|
||||
FOREIGN KEY (`host_id` )
|
||||
REFERENCES `kea_host_reservation`.`hosts` (`host_id` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS dhcp4_options (
|
||||
option_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
code TINYINT UNSIGNED NOT NULL,
|
||||
value BLOB NULL,
|
||||
formatted_value TEXT NULL,
|
||||
space VARCHAR(128) NULL,
|
||||
persistent TINYINT(1) NOT NULL DEFAULT 0,
|
||||
dhcp_client_class VARCHAR(128) NULL,
|
||||
dhcp4_subnet_id INT NULL,
|
||||
host_id INT UNSIGNED NULL,
|
||||
PRIMARY KEY (option_id),
|
||||
UNIQUE INDEX option_id_UNIQUE (option_id ASC),
|
||||
INDEX fk_options_host1_idx (host_id ASC),
|
||||
CONSTRAINT fk_options_host1 FOREIGN KEY (host_id)
|
||||
REFERENCES hosts (host_id)
|
||||
ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
) ENGINE=INNODB;
|
||||
-- -----------------------------------------------------
|
||||
-- Table `kea_host_reservation`.`dhcp4_options`
|
||||
-- Table `dhcp6_options`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `kea_host_reservation`.`dhcp4_options` (
|
||||
`option_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
|
||||
`code` TINYINT UNSIGNED NOT NULL ,
|
||||
`value` BLOB NULL ,
|
||||
`formatted_value` TEXT NULL ,
|
||||
`space` VARCHAR(128) NULL ,
|
||||
`persistent` TINYINT(1) NOT NULL DEFAULT 0 ,
|
||||
`dhcp_client_class` VARCHAR(128) NULL ,
|
||||
`dhcp4_subnet_id` INT NULL ,
|
||||
`host_id` INT UNSIGNED NULL ,
|
||||
PRIMARY KEY (`option_id`) ,
|
||||
UNIQUE INDEX `option_id_UNIQUE` (`option_id` ASC) ,
|
||||
INDEX `fk_options_host1_idx` (`host_id` ASC) ,
|
||||
CONSTRAINT `fk_options_host1`
|
||||
FOREIGN KEY (`host_id` )
|
||||
REFERENCES `kea_host_reservation`.`hosts` (`host_id` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `kea_host_reservation`.`dhcp6_options`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `kea_host_reservation`.`dhcp6_options` (
|
||||
`option_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
|
||||
`code` INT UNSIGNED NOT NULL ,
|
||||
`value` BLOB NULL ,
|
||||
`formatted_value` TEXT NULL ,
|
||||
`space` VARCHAR(128) NULL ,
|
||||
`persistent` TINYINT(1) NOT NULL DEFAULT 0 ,
|
||||
`dhcp_client_class` VARCHAR(128) NULL ,
|
||||
`dhcp6_subnet_id` INT NULL ,
|
||||
`host_id` INT UNSIGNED NULL ,
|
||||
PRIMARY KEY (`option_id`) ,
|
||||
UNIQUE INDEX `option_id_UNIQUE` (`option_id` ASC) ,
|
||||
INDEX `fk_options_host1_idx` (`host_id` ASC) ,
|
||||
CONSTRAINT `fk_options_host10`
|
||||
FOREIGN KEY (`host_id` )
|
||||
REFERENCES `kea_host_reservation`.`hosts` (`host_id` )
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
USE `kea_host_reservation` ;
|
||||
USE `kea_host_reservation`;
|
||||
CREATE TABLE IF NOT EXISTS dhcp6_options (
|
||||
option_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
code INT UNSIGNED NOT NULL,
|
||||
value BLOB NULL,
|
||||
formatted_value TEXT NULL,
|
||||
space VARCHAR(128) NULL,
|
||||
persistent TINYINT(1) NOT NULL DEFAULT 0,
|
||||
dhcp_client_class VARCHAR(128) NULL,
|
||||
dhcp6_subnet_id INT NULL,
|
||||
host_id INT UNSIGNED NULL,
|
||||
PRIMARY KEY (option_id),
|
||||
UNIQUE INDEX option_id_UNIQUE (option_id ASC),
|
||||
INDEX fk_options_host1_idx (host_id ASC),
|
||||
CONSTRAINT fk_options_host10 FOREIGN KEY (host_id)
|
||||
REFERENCES hosts (host_id)
|
||||
ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
) ENGINE=INNODB;
|
||||
|
||||
DELIMITER $$
|
||||
USE `kea_host_reservation`$$
|
||||
|
||||
|
||||
CREATE TRIGGER `host_BDEL` BEFORE DELETE ON hosts FOR EACH ROW
|
||||
CREATE TRIGGER host_BDEL BEFORE DELETE ON hosts FOR EACH ROW
|
||||
-- Edit trigger body code below this line. Do not edit lines above this one
|
||||
BEGIN
|
||||
DELETE FROM `ipv6_reservations` WHERE `ipv6_reservations`.host_id = OLD.host_id;
|
||||
DELETE FROM ipv6_reservations WHERE ipv6_reservations.host_id = OLD.host_id;
|
||||
END
|
||||
$$
|
||||
|
||||
|
||||
DELIMITER ;
|
||||
|
||||
|
||||
SET SQL_MODE=@OLD_SQL_MODE;
|
||||
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
||||
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
|
||||
|
||||
|
||||
UPDATE schema_version
|
||||
SET version = '3', minor = '0';
|
||||
# This line concludes database upgrade to version 3.0.
|
||||
|
||||
# Notes:
|
||||
|
Reference in New Issue
Block a user