Skip to content

Commit

Permalink
Run cpdb --update
Browse files Browse the repository at this point in the history
cpdb --create creates the database but --update updates it to the latest
schema. The installer can also remove the marker file
/var/lib/candlepin/cpdb_update_done to trigger a schema migration.
  • Loading branch information
ekohl authored and ehelms committed Jan 13, 2020
1 parent 2f08eeb commit fadb503
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
19 changes: 16 additions & 3 deletions manifests/database/postgresql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
default => ''
}

exec { 'cpdb':
exec { 'cpdb create':
path => '/usr/share/candlepin:/bin',
command => "cpdb --create \
--schema-only \
Expand All @@ -66,12 +66,25 @@
>> ${log_dir}/cpdb.log \
2>&1 && touch /var/lib/candlepin/cpdb_done",
creates => '/var/lib/candlepin/cpdb_done',
before => Service['tomcat'],
require => Concat['/etc/candlepin/candlepin.conf'],
} ->

exec { 'cpdb update':
path => '/usr/share/candlepin:/bin',
command => "cpdb --update \
--dbhost=${db_host} \
--dbport=${db_port} \
--database='${db_name}${ssl_options}' \
--user='${db_user}' \
--password='${db_password}' \
>> ${log_dir}/cpdb.log \
2>&1 && touch /var/lib/candlepin/cpdb_update_done",
creates => '/var/lib/candlepin/cpdb_update_done',
}

# if both manage_db and init_db enforce order of resources
if $manage_db {
Postgresql::Server::Db[$db_name] -> Exec['cpdb']
Postgresql::Server::Db[$db_name] -> Exec['cpdb create']
}
}
}
11 changes: 10 additions & 1 deletion spec/classes/candlepin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@
# database
it { is_expected.not_to contain_class('candlepin::database::mysql') }
it { is_expected.to contain_class('candlepin::database::postgresql') }
it { is_expected.to contain_exec('cpdb').that_subscribes_to('Package[candlepin]').that_comes_before('Service[tomcat]') }
it 'migrates the database' do
is_expected.to contain_exec('cpdb create')
.that_subscribes_to(['Package[candlepin]', 'Concat[/etc/candlepin/candlepin.conf]'])
.that_requires('Postgresql::Server::Db[candlepin]')
.that_notifies('Service[tomcat]')
is_expected.to contain_exec('cpdb update')
.that_subscribes_to(['Package[candlepin]', 'Concat[/etc/candlepin/candlepin.conf]'])
.that_requires('Exec[cpdb create]')
.that_notifies('Service[tomcat]')
end
it { is_expected.to contain_postgresql__server__db('candlepin') }
it { is_expected.to contain_postgresql__server__role('candlepin').that_comes_before('Postgresql::Server::Database[candlepin]') }

Expand Down

0 comments on commit fadb503

Please sign in to comment.