From a8c8b959723c8d28f8a58cbf4831a2b6740100f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20Mudr=C3=A1k?= Date: Fri, 27 Jun 2014 14:38:11 +0200 Subject: [PATCH] Add support for optional db.namePrefix setting Currently, the default database name is the same as the Moodle instance's name. This is suboptimal for development setups where the database engine is used for other projects as well (Moodle developer can easily have Mahara or Mediawiki databases present as well, for example). I believe it's a good idea to make it clear that certain database is under mdk's control. Having a prefix (such as `mdk_`) seems to work well. --- config-dist.json | 2 ++ lib/commands/create.py | 4 ++++ lib/moodle.py | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/config-dist.json b/config-dist.json index 99ad039..1412ea4 100644 --- a/config-dist.json +++ b/config-dist.json @@ -33,6 +33,8 @@ // Database access "db": { + // Name prefix for all databases created by mdk. Affects the database name only, not the tables. + "namePrefix": "", "mysqli": { "host": "localhost", "port": "3306", diff --git a/lib/commands/create.py b/lib/commands/create.py index ec668fd..259e638 100644 --- a/lib/commands/create.py +++ b/lib/commands/create.py @@ -183,6 +183,10 @@ class CreateCommand(Command): # Checking database dbname = re.sub(r'[^a-zA-Z0-9]', '', name).lower()[:28] + prefixDbname = self.C.get('db.namePrefix') + if prefixDbname == None: + prefixDbname = ''; + dbname = prefixDbname + dbname db = DB(engine, self.C.get('db.%s' % engine)) dropDb = False if db.dbexists(dbname): diff --git a/lib/moodle.py b/lib/moodle.py index 3d5da43..f82ff79 100644 --- a/lib/moodle.py +++ b/lib/moodle.py @@ -384,6 +384,10 @@ class Moodle(object): raise InstallException('Cannot install instance without knowing where the data directory is') if dbname == None: dbname = re.sub(r'[^a-zA-Z0-9]', '', self.identifier).lower()[:28] + prefixDbname = C.get('db.namePrefix') + if prefixDbname == None: + prefixDbname = ''; + dbname = prefixDbname + dbname if engine == None: engine = C.get('defaultEngine') if fullname == None: -- 2.11.0