~johnsca/charms/precise/thinkup/charm-proof

« back to all changes in this revision

Viewing changes to hooks/db-relation-changed

  • Committer: Nathan Osman
  • Date: 2011-11-24 06:42:39 UTC
  • Revision ID: admin@quickmediasolutions.com-20111124064239-0ew1zn9tfload198
Added guard to ensure that SQL commands are only executed once.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
db_name='$DATABASE'
31
31
EOD
32
32
 
33
 
# Execute the SQL that creates the tables
34
 
juju-log "Creating database tables and finalizing configuration"
35
 
cat > /tmp/enable_open_registration.sql <<EOD
 
33
# We only want the SQL tables entered into the database _once_ and
 
34
# after that the step needs to be skipped. So we create a file in
 
35
# /opt the first time and check for it in later iterations.
 
36
if [ ! -f /opt/created_database_tables ] ; then
 
37
    
 
38
    # Execute the SQL that creates the tables
 
39
    juju-log "Creating database tables and finalizing configuration"
 
40
    cat > /tmp/enable_open_registration.sql <<EOD
36
41
INSERT INTO $DATABASE.tu_options (namespace, option_name, option_value, last_updated, created) VALUES ('application_options', 'is_registration_open', 'true', NOW(), NOW());
37
42
UPDATE $DATABASE.tu_plugins SET is_active = 1;
38
43
EOD
39
 
cat /var/www/install/sql/build-db_mysql.sql /tmp/enable_open_registration.sql | mysql -u$DB_USER -p$DB_PASS -h$DB_HOST $DATABASE
 
44
    cat /var/www/install/sql/build-db_mysql.sql /tmp/enable_open_registration.sql | mysql -u$DB_USER -p$DB_PASS -h$DB_HOST $DATABASE
 
45
    
 
46
    # Create the file signaling that the tables have been created
 
47
    # (Added bonus: if there was an error inserting the tables, this
 
48
    # line will not be reached and will be retried next time!)
 
49
    echo "" >/opt/created_database_tables
 
50
fi