Commit 5b177a4e authored by frankiejol's avatar frankiejol
Browse files

refactor(install): base images and domain instances constraints

parent f9f24228
......@@ -1792,6 +1792,15 @@ sub _sql_create_tables($self) {
}
]
,
[
file_base_images => {
id => 'integer PRIMARY KEY AUTO_INCREMENT'
,id_domain => 'integer NOT NULL references `domains` (`id`) ON DELETE CASCADE'
,file_base_img => ' varchar(255) DEFAULT NULL'
,target => 'varchar(64) DEFAULT NULL'
}
]
,
[
volumes => {
id => 'integer PRIMARY KEY AUTO_INCREMENT',
......@@ -1852,6 +1861,11 @@ sub _clean_db_leftovers($self) {
." ( SELECT id FROM domains ) ");
;
}
for my $table ('bases_vm' ,'domain_instances') {
$self->_delete_limit("FROM $table WHERE id_vm NOT IN "
." ( SELECT id FROM vms) ");
;
}
for my $table ('grants_user') {
my $sth_select = $dbh->prepare("SELECT count(*) FROM $table WHERE id_user NOT IN "
." ( SELECT id FROM users ) ");
......@@ -2097,7 +2111,6 @@ sub _upgrade_tables {
# return if $CONNECTOR->dbh->{Driver}{Name} !~ /mysql/i;
$self->_upgrade_table("base_xml",'xml','TEXT');
$self->_upgrade_table('file_base_images','target','varchar(64) DEFAULT NULL');
$self->_upgrade_table('vms','vm_type',"char(20) NOT NULL DEFAULT 'KVM'");
$self->_upgrade_table('vms','connection_args',"text DEFAULT NULL");
......@@ -2214,6 +2227,11 @@ sub _upgrade_tables {
$self->_upgrade_table('grants_user', 'id_user', 'int not null references `users` (`id`) ON DELETE CASCADE');
$self->_upgrade_table('bases_vm','id_vm','int not null references `vms` (`id`) ON DELETE CASCADE');
$self->_upgrade_table('bases_vm','id_domain','int not null references `domains` (`id`) ON DELETE CASCADE');
$self->_upgrade_table('domain_instances','id_vm','int not null references `vms` (`id`) ON DELETE CASCADE');
$self->_upgrade_users_table();
}
......
CREATE TABLE `file_base_images` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_domain` int(11),
`file_base_img` varchar(255) DEFAULT NULL,
`target` varchar(64) DEFAULT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `file_base_images` (
`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT
, `id_domain` integer
, `file_base_img` varchar(255) DEFAULT NULL
, `target` varchar(64) DEFAULT NULL
);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment