mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-23 17:33:56 +03:00
F #4937: Change schema code to database backend
This commit is contained in:
parent
5be92e323d
commit
38cb96edcd
@ -1158,6 +1158,7 @@ ONEDB_FILES="src/onedb/fsck.rb \
|
||||
src/onedb/onedb.rb \
|
||||
src/onedb/onedb_backend.rb \
|
||||
src/onedb/sqlite2mysql.rb \
|
||||
src/onedb/database_schema.rb \
|
||||
src/onedb/fsck"
|
||||
|
||||
ONEDB_SHARED_MIGRATOR_FILES="src/onedb/shared/2.0_to_2.9.80.rb \
|
||||
@ -1198,8 +1199,7 @@ ONEDB_SHARED_MIGRATOR_FILES="src/onedb/shared/2.0_to_2.9.80.rb \
|
||||
src/onedb/shared/4.11.80_to_4.90.0.rb \
|
||||
src/onedb/shared/4.90.0_to_5.2.0.rb"
|
||||
|
||||
ONEDB_LOCAL_MIGRATOR_FILES="src/onedb/local/db_schema.rb \
|
||||
src/onedb/local/4.5.80_to_4.7.80.rb \
|
||||
ONEDB_LOCAL_MIGRATOR_FILES="src/onedb/local/4.5.80_to_4.7.80.rb \
|
||||
src/onedb/local/4.7.80_to_4.9.80.rb \
|
||||
src/onedb/local/4.9.80_to_4.10.3.rb \
|
||||
src/onedb/local/4.10.3_to_4.11.80.rb \
|
||||
|
98
src/onedb/database_schema.rb
Normal file
98
src/onedb/database_schema.rb
Normal file
@ -0,0 +1,98 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2017, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
class OneDBBacKEnd
|
||||
SCHEMA = {
|
||||
cluster_pool: "oid INTEGER PRIMARY KEY, name VARCHAR(128), " <<
|
||||
"body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, " <<
|
||||
"group_u INTEGER, other_u INTEGER, UNIQUE(name)",
|
||||
cluster_datastore_relation: "cid INTEGER, oid INTEGER, " <<
|
||||
"PRIMARY KEY(cid, oid)",
|
||||
cluster_network_relation: "cid INTEGER, oid INTEGER, " <<
|
||||
"PRIMARY KEY(cid, oid)",
|
||||
datastore_pool: "oid INTEGER PRIMARY KEY, name VARCHAR(128), " <<
|
||||
"body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, " <<
|
||||
"group_u INTEGER, other_u INTEGER",
|
||||
cluster_vnc_bitmap: "id INTEGER, map LONGTEXT, PRIMARY KEY(id)",
|
||||
host_pool: "oid INTEGER PRIMARY KEY, " <<
|
||||
"name VARCHAR(128), body MEDIUMTEXT, state INTEGER, " <<
|
||||
"last_mon_time INTEGER, uid INTEGER, gid INTEGER, " <<
|
||||
"owner_u INTEGER, group_u INTEGER, other_u INTEGER, " <<
|
||||
"cid INTEGER",
|
||||
image_pool: "oid INTEGER PRIMARY KEY, name VARCHAR(128), " <<
|
||||
"body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, " <<
|
||||
"group_u INTEGER, other_u INTEGER, UNIQUE(name,uid)",
|
||||
network_pool: "oid INTEGER PRIMARY KEY, name VARCHAR(128), " <<
|
||||
"body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, " <<
|
||||
"group_u INTEGER, other_u INTEGER, pid INTEGER, UNIQUE(name,uid)",
|
||||
user_quotas: "user_oid INTEGER PRIMARY KEY, body MEDIUMTEXT",
|
||||
group_quotas: "group_oid INTEGER PRIMARY KEY, body MEDIUMTEXT"
|
||||
}
|
||||
|
||||
VERSION_SCHEMA = {
|
||||
"5.3.80" => {
|
||||
vmgroup_pool: "oid INTEGER PRIMARY KEY, name VARCHAR(128), " <<
|
||||
"body MEDIUMTEXT, uid INTEGER, gid INTEGER, " <<
|
||||
"owner_u INTEGER, group_u INTEGER, other_u INTEGER, " <<
|
||||
"UNIQUE(name,uid)",
|
||||
host_pool: "oid INTEGER PRIMARY KEY, name VARCHAR(128), " <<
|
||||
"body MEDIUMTEXT, state INTEGER, last_mon_time INTEGER, " <<
|
||||
"uid INTEGER, gid INTEGER, owner_u INTEGER, " <<
|
||||
"group_u INTEGER, other_u INTEGER, cid INTEGER",
|
||||
vm_pool: "oid INTEGER PRIMARY KEY, name VARCHAR(128), " <<
|
||||
"body MEDIUMTEXT, uid INTEGER, gid INTEGER, " <<
|
||||
"last_poll INTEGER, state INTEGER, lcm_state INTEGER, " <<
|
||||
"owner_u INTEGER, group_u INTEGER, other_u INTEGER"
|
||||
}
|
||||
}
|
||||
|
||||
LATEST_DB_VERSION = "5.3.80"
|
||||
|
||||
def get_schema(type, version = nil)
|
||||
if !version
|
||||
if self.respond_to?(:db_version)
|
||||
version = db_version
|
||||
else
|
||||
version = LATEST_DB_VERSION
|
||||
end
|
||||
end
|
||||
|
||||
version_schema = VERSION_SCHEMA[version] || {}
|
||||
schema = SCHEMA.merge(version_schema)[type]
|
||||
|
||||
if !schema
|
||||
STDERR.puts "Schema not found (#{type}) for version #{version}"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
schema
|
||||
end
|
||||
|
||||
def create_table(type, name = nil, version = nil)
|
||||
if name
|
||||
n = name.to_s
|
||||
else
|
||||
n = type.to_s
|
||||
end
|
||||
|
||||
schema = get_schema(type, version)
|
||||
|
||||
sql = "CREATE TABLE #{n} (#{schema});"
|
||||
|
||||
@db.run sql
|
||||
end
|
||||
end
|
||||
|
@ -101,33 +101,6 @@ EOT
|
||||
FEDERATED_TABLES = ["group_pool", "user_pool", "acl", "zone_pool",
|
||||
"vdc_pool", "marketplace_pool", "marketplaceapp_pool"].freeze
|
||||
|
||||
SCHEMA = {
|
||||
cluster_pool: "oid INTEGER PRIMARY KEY, name VARCHAR(128), " <<
|
||||
"body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, " <<
|
||||
"group_u INTEGER, other_u INTEGER, UNIQUE(name)",
|
||||
cluster_datastore_relation: "cid INTEGER, oid INTEGER, " <<
|
||||
"PRIMARY KEY(cid, oid)",
|
||||
cluster_network_relation: "cid INTEGER, oid INTEGER, " <<
|
||||
"PRIMARY KEY(cid, oid)",
|
||||
datastore_pool: "oid INTEGER PRIMARY KEY, name VARCHAR(128), " <<
|
||||
"body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, " <<
|
||||
"group_u INTEGER, other_u INTEGER",
|
||||
cluster_vnc_bitmap: "id INTEGER, map LONGTEXT, PRIMARY KEY(id)",
|
||||
host_pool: "oid INTEGER PRIMARY KEY, " <<
|
||||
"name VARCHAR(128), body MEDIUMTEXT, state INTEGER, " <<
|
||||
"last_mon_time INTEGER, uid INTEGER, gid INTEGER, " <<
|
||||
"owner_u INTEGER, group_u INTEGER, other_u INTEGER, " <<
|
||||
"cid INTEGER",
|
||||
image_pool: "oid INTEGER PRIMARY KEY, name VARCHAR(128), " <<
|
||||
"body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, " <<
|
||||
"group_u INTEGER, other_u INTEGER, UNIQUE(name,uid)",
|
||||
network_pool: "oid INTEGER PRIMARY KEY, name VARCHAR(128), " <<
|
||||
"body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, " <<
|
||||
"group_u INTEGER, other_u INTEGER, pid INTEGER, UNIQUE(name,uid)",
|
||||
user_quotas: "user_oid INTEGER PRIMARY KEY, body MEDIUMTEXT",
|
||||
group_quotas: "group_oid INTEGER PRIMARY KEY, body MEDIUMTEXT"
|
||||
}
|
||||
|
||||
def tables
|
||||
TABLES
|
||||
end
|
||||
@ -136,27 +109,6 @@ EOT
|
||||
FEDERATED_TABLES
|
||||
end
|
||||
|
||||
def create_table(type, name = nil)
|
||||
if name
|
||||
n = name.to_s
|
||||
else
|
||||
n = type.to_s
|
||||
end
|
||||
|
||||
schema = SCHEMA[type]
|
||||
|
||||
if !schema
|
||||
STDERR.puts "Schema not found (#{type})"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
sql = "CREATE TABLE #{n} (#{schema});"
|
||||
|
||||
STDERR.puts sql
|
||||
|
||||
@db.run sql
|
||||
end
|
||||
|
||||
def nokogiri_doc(body)
|
||||
Nokogiri::XML(body, nil, NOKOGIRI_ENCODING) do |c|
|
||||
c.default_xml.noblanks
|
||||
|
@ -23,7 +23,6 @@ require 'pathname'
|
||||
require 'opennebula'
|
||||
|
||||
$: << File.dirname(__FILE__)
|
||||
require 'db_schema'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
@ -43,6 +42,8 @@ module Migrator
|
||||
|
||||
feature_5005()
|
||||
|
||||
feature_2347()
|
||||
|
||||
log_time()
|
||||
|
||||
return true
|
||||
@ -65,7 +66,7 @@ module Migrator
|
||||
############################################################################
|
||||
def feature_4901
|
||||
@db.run "ALTER TABLE host_pool RENAME TO old_host_pool;"
|
||||
@db.run host_pool_schema()
|
||||
create_table(:host_pool)
|
||||
|
||||
@db.transaction do
|
||||
@db.fetch("SELECT * FROM old_host_pool") do |row|
|
||||
@ -102,7 +103,7 @@ module Migrator
|
||||
def feature_5005
|
||||
#TODO ADD VALUES TO HISTORY POOL TABLE
|
||||
@db.run "ALTER TABLE vm_pool RENAME TO old_vm_pool;"
|
||||
@db.run vm_pool_schema()
|
||||
create_table(:vm_pool)
|
||||
|
||||
@db.transaction do
|
||||
@db.fetch("SELECT * FROM old_vm_pool") do |row|
|
||||
@ -132,4 +133,8 @@ module Migrator
|
||||
|
||||
@db.run "DROP TABLE old_vm_pool;"
|
||||
end
|
||||
|
||||
def feature_2347
|
||||
create_table(:vmgroup_pool)
|
||||
end
|
||||
end
|
||||
|
@ -1,66 +0,0 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'set'
|
||||
require 'base64'
|
||||
require 'zlib'
|
||||
require 'pathname'
|
||||
|
||||
require 'opennebula'
|
||||
|
||||
include OpenNebula
|
||||
|
||||
module Migrator
|
||||
##############################################################################
|
||||
# DB schema for OpenNebula tables, each function may return the schema for
|
||||
# each opennebula version
|
||||
##############################################################################
|
||||
def host_pool_schema
|
||||
case db_version()
|
||||
when "4.5.80"
|
||||
when "4.7.80"
|
||||
when "4.9.80"
|
||||
when "4.10.3"
|
||||
when "4.11.80"
|
||||
when "4.13.80"
|
||||
when "4.13.85"
|
||||
when "4.90.0"
|
||||
when "5.3.80"
|
||||
'CREATE TABLE host_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), '\
|
||||
'body MEDIUMTEXT, state INTEGER, last_mon_time INTEGER, uid INTEGER, '\
|
||||
'gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, '\
|
||||
'cid INTEGER);'
|
||||
end
|
||||
end
|
||||
|
||||
def vm_pool_schema
|
||||
case db_version()
|
||||
when "4.5.80"
|
||||
when "4.7.80"
|
||||
when "4.9.80"
|
||||
when "4.10.3"
|
||||
when "4.11.80"
|
||||
when "4.13.80"
|
||||
when "4.13.85"
|
||||
when "4.90.0"
|
||||
when "5.3.80"
|
||||
'CREATE TABLE vm_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), '\
|
||||
'body MEDIUMTEXT, uid INTEGER, gid INTEGER, last_poll INTEGER, '\
|
||||
'state INTEGER, lcm_state INTEGER, owner_u INTEGER, group_u INTEGER, '\
|
||||
'other_u INTEGER);'
|
||||
end
|
||||
end
|
||||
end
|
@ -17,6 +17,7 @@
|
||||
require 'time'
|
||||
require 'rubygems'
|
||||
require 'cgi'
|
||||
require 'database_schema'
|
||||
|
||||
begin
|
||||
require 'sequel'
|
||||
|
Loading…
Reference in New Issue
Block a user