forked from quakenet/newserv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb-slave.c
42 lines (35 loc) · 1.35 KB
/
db-slave.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "../dbapi2/dbapi2.h"
#include "../core/error.h"
#include "trusts.h"
extern DBAPIConn *trustsdb;
void createtrusttables(int);
void trusts_replication_complete(int);
void trusts_replication_createtables(void) {
createtrusttables(TABLES_REPLICATION);
trustsdb->squery(trustsdb, "DELETE FROM ?", "T", "replication_groups");
trustsdb->squery(trustsdb, "DELETE FROM ?", "T", "replication_hosts");
}
static void tr_complete(const DBAPIResult *r, void *tag) {
if(!r) {
trusts_replication_complete(1);
} else {
if(!r->success) {
Error("trusts_slave", ERR_ERROR, "A error occured executing the rename table query.");
trusts_replication_complete(2);
} else {
Error("trusts_slave", ERR_INFO, "Migration table copying complete.");
trusts_replication_complete(0);
}
r->clear(r);
}
}
void trusts_replication_swap(void) {
trusts_closedb(0);
Error("trusts_slave", ERR_INFO, "Copying tables...");
trustsdb->squery(trustsdb, "BEGIN TRANSACTION", "");
trustsdb->squery(trustsdb, "DROP TABLE ?", "T", "groups");
trustsdb->squery(trustsdb, "ALTER TABLE ? RENAME TO ?", "Ts", "replication_groups", "groups");
trustsdb->squery(trustsdb, "DROP TABLE ?", "T", "hosts");
trustsdb->squery(trustsdb, "ALTER TABLE ? RENAME TO ?", "Ts", "replication_hosts", "hosts");
trustsdb->query(trustsdb, tr_complete, NULL, "COMMIT", "");
}