mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 11:40:27 +03:00
New command-line command 'upgrade'.
This commit is contained in:
parent
8a71e2e557
commit
45be9a1cb1
11
data.c
11
data.c
@ -19,7 +19,7 @@ double db_layout = 2.3;
|
||||
|
||||
int db_upgrade(d_char **error);
|
||||
|
||||
int srv_open(char *basedir)
|
||||
int srv_open(char *basedir, int auto_upgrade)
|
||||
/* opens a server */
|
||||
{
|
||||
int ret = 0;
|
||||
@ -69,7 +69,14 @@ int srv_open(char *basedir)
|
||||
error = xs_fmt("DEBUG level set to %d from environment", dbglevel);
|
||||
}
|
||||
|
||||
ret = db_upgrade(&error);
|
||||
if (auto_upgrade)
|
||||
ret = db_upgrade(&error);
|
||||
else {
|
||||
if (xs_number_get(xs_dict_get(srv_config, "layout")) < db_layout) {
|
||||
ret = 0;
|
||||
error = xs_fmt("ERROR: db layout changed - execute 'snac upgrade' first");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
16
main.c
16
main.c
@ -16,6 +16,7 @@ int usage(void)
|
||||
printf("Commands:\n");
|
||||
printf("\n");
|
||||
printf("init [{basedir}] Initializes the database\n");
|
||||
printf("upgrade {basedir} Upgrade to a new version\n");
|
||||
printf("adduser {basedir} [{uid}] Adds a new user\n");
|
||||
printf("httpd {basedir} Starts the HTTPD daemon\n");
|
||||
printf("purge {basedir} Purges old data\n");
|
||||
@ -76,6 +77,19 @@ int main(int argc, char *argv[])
|
||||
return initdb(basedir);
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "upgrade") == 0) {
|
||||
int ret;
|
||||
|
||||
/* database upgrade */
|
||||
if ((basedir = GET_ARGV()) == NULL)
|
||||
return usage();
|
||||
|
||||
if ((ret = srv_open(basedir, 1)) == 1)
|
||||
srv_log(xs_dup("OK"));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "markdown") == 0) {
|
||||
/* undocumented, for testing only */
|
||||
xs *c = xs_readall(stdin);
|
||||
@ -88,7 +102,7 @@ int main(int argc, char *argv[])
|
||||
if ((basedir = GET_ARGV()) == NULL)
|
||||
return usage();
|
||||
|
||||
if (!srv_open(basedir)) {
|
||||
if (!srv_open(basedir, 0)) {
|
||||
srv_log(xs_fmt("error opening database at %s", basedir));
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user