~marcoceppi/charms/precise/mysql/fix-metadata

« back to all changes in this revision

Viewing changes to hooks/db-relation-joined

  • Committer: Clint Byrum
  • Date: 2012-11-01 22:16:50 UTC
  • Revision ID: clint@ubuntu.com-20121101221650-c04www27atctzvtj
Make a sane decision when the database already exists, rather than exitting blindly. Helps with idempotency of add/remove relation and helps with promoting a slave to master

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
  print "%s exists, assuming configuration done" % slave_configured_path
24
24
  sys.exit(0)
25
25
 
26
 
if not slave and not broken and not admin:
27
 
  # Find existing databases
28
 
  cursor.execute("show databases")
29
 
  databases = [i[0] for i in cursor.fetchall()]
30
 
  if database_name in databases:
31
 
    print "database exists, assuming configuration has happened already"
32
 
    sys.exit(0)
33
 
 
34
26
# Database is created just before relation-set in case other steps fail
35
27
 
36
28
# Create database user and grant access
78
70
# Create new database or touch slave.configured file
79
71
if slave:
80
72
    open(slave_configured_path,'w').close()
81
 
else:
82
 
    if not broken and not admin:
83
 
        runsql("create database `%s` character set utf8" % database_name)
84
 
        with open(database_name_file, 'w') as dbname:
85
 
            dbname.write(database_name)
 
73
elif not broken and not admin:
 
74
  # Find existing databases
 
75
  cursor.execute("show databases")
 
76
  databases = [i[0] for i in cursor.fetchall()]
 
77
  if database_name in databases:
 
78
      print "database exists already"
 
79
  else:
 
80
      if not broken and not admin:
 
81
          runsql("create database `%s` character set utf8" % database_name)
 
82
          with open(database_name_file, 'w') as dbname:
 
83
              dbname.write(database_name)
86
84
 
87
85
if broken:
88
86
    os.unlink(broken_path)