summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-03-18 11:46:14 -0500
committerAdam <Adam@anope.org>2013-03-18 12:16:51 -0500
commit731912f01eb14d811575c492dc64b60084bd412c (patch)
treed7d0219aa03bfa6187599a4d380ec701099fd827
parent51963915ba17dc4e8e13d7430f1dcbddcebe9e3d (diff)
Add db_sql:import config option so we can know for sure whether or not we want a database import
-rw-r--r--data/example.conf16
-rw-r--r--modules/database/db_sql.cpp12
-rw-r--r--modules/database/db_sql_live.cpp3
3 files changed, 28 insertions, 3 deletions
diff --git a/data/example.conf b/data/example.conf
index e030a24f4..9f7b27576 100644
--- a/data/example.conf
+++ b/data/example.conf
@@ -1109,11 +1109,11 @@ db_flatfile
* This module allows saving and loading databases using one of the SQL engines.
* This module reads and writes to SQL in real time. Changes to the SQL tables
* will be immediately reflected into Anope. This module should not be loaded
- * in conjunction with db_sql, except during the initial import of existing
- * databases to SQL.
+ * in conjunction with db_sql.
*/
#module { name = "db_sql_live" }
+/* Configuration block for both db_sql and db_sql_live */
db_sql
{
/*
@@ -1127,6 +1127,18 @@ db_sql
* Do not use the same prefix for other programs.
*/
#prefix = "anope_db_"
+
+ /* Whether or not to import data from another database module in to SQL on startup.
+ * If you enable this, be sure that the database services is configured to use is
+ * empty and that another database module to import from is loaded before db_sql.
+ * After you enable this and do a database import you should disable it for
+ * subsequent restarts.
+ *
+ * Note that you can not import databases using db_sql_live. If you want to import
+ * databases and use db_sql_live you should import them using db_sql, then shut down
+ * and start services with db_sql_live.
+ */
+ import = false
}
/*
diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp
index ab6a1b259..78b05a52d 100644
--- a/modules/database/db_sql.cpp
+++ b/modules/database/db_sql.cpp
@@ -59,6 +59,8 @@ class DBSQL : public Module, public Pipe
ServiceReference<Provider> sql;
SQLSQLInterface sqlinterface;
Anope::string prefix;
+ bool import;
+
std::set<Serializable *> updated_items;
bool shutting_down;
bool loading_databases;
@@ -95,6 +97,9 @@ class DBSQL : public Module, public Pipe
ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
this->OnReload();
+
+ if (ModuleManager::FindModule("db_sql_live") != NULL)
+ throw ModuleException("db_sql can not be loaded after db_sql_live");
}
void OnNotify() anope_override
@@ -113,6 +118,10 @@ class DBSQL : public Module, public Pipe
obj->UpdateCache(data);
+ /* If we didn't load these objects and we don't want to import just update the cache and continue */
+ if (!this->loaded && !this->imported && !this->import)
+ continue;
+
Serialize::Type *s_type = obj->GetSerializableType();
if (!s_type)
continue;
@@ -126,7 +135,7 @@ class DBSQL : public Module, public Pipe
this->RunBackground(insert, new ResultSQLSQLInterface(this, obj));
else
{
- /* On the first loop we may be importing objects from another database module, so don't do asynchronous
+ /* We are importing objects from another database module, so don't do asynchronous
* queries in case the core has to shut down, it will cut short the import
*/
Result r = this->sql->RunQuery(insert);
@@ -146,6 +155,7 @@ class DBSQL : public Module, public Pipe
Anope::string engine = config.ReadValue("db_sql", "engine", "", 0);
this->sql = ServiceReference<Provider>("SQL::Provider", engine);
this->prefix = config.ReadValue("db_sql", "prefix", "anope_db_", 0);
+ this->import = config.ReadFlag("db_sql", "import", "false", 0);
}
void OnShutdown() anope_override
diff --git a/modules/database/db_sql_live.cpp b/modules/database/db_sql_live.cpp
index 62f1c0ca4..c7c48937a 100644
--- a/modules/database/db_sql_live.cpp
+++ b/modules/database/db_sql_live.cpp
@@ -76,6 +76,9 @@ class DBMySQL : public Module, public Pipe
ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
OnReload();
+
+ if (ModuleManager::FindFirstOf(DATABASE) != this)
+ throw ModuleException("If db_sql_live is loaded it must be the first database module loaded.");
}
void OnNotify() anope_override