From: Michal Fojtik <mfoj...@redhat.com> Currently everytime we add or remove attributes from DB, users need to rerun the 'rake' task to recreate the database.
This patch will make possible to update the DB schema without executing the rake task. The 'migrations' extension in Sequel will check the 'schema_version' table and apply all migrations >= than the current schema. Migrations must be prefixed with the schema number in chronological order and they are stored in server/lib/db/migrations. Signed-off-by: Michal fojtik <mfoj...@redhat.com> --- server/lib/db.rb | 18 +++++++++++++++++ .../migrations/1_add_realm_to_machine_template.rb | 23 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 server/lib/db/migrations/1_add_realm_to_machine_template.rb diff --git a/server/lib/db.rb b/server/lib/db.rb index 694450d..33217a3 100644 --- a/server/lib/db.rb +++ b/server/lib/db.rb @@ -1,3 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you 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. + module Deltacloud def self.test_environment? @@ -8,6 +23,7 @@ module Deltacloud require 'sequel' require 'logger' Sequel::Model.plugin :validation_class_methods + Sequel.extension :migration end if RUBY_PLATFORM == 'java' @@ -77,6 +93,8 @@ module Deltacloud column :volume_config, :string column :volume_image, :string } + + Sequel::Migrator.apply(db, File.join(File.dirname(__FILE__), 'db', 'migrations')) end end diff --git a/server/lib/db/migrations/1_add_realm_to_machine_template.rb b/server/lib/db/migrations/1_add_realm_to_machine_template.rb new file mode 100644 index 0000000..8261efc --- /dev/null +++ b/server/lib/db/migrations/1_add_realm_to_machine_template.rb @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you 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. + +Sequel.migration do + up do + add_column :entities, :realm, String + end + down do + drop_column :entities, :realm + end +end -- 1.8.1