mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 21:35:04 +00:00
New command-line command 'upgrade'.
This commit is contained in:
parent
8a71e2e557
commit
45be9a1cb1
3 changed files with 25 additions and 4 deletions
11
data.c
11
data.c
|
@ -19,7 +19,7 @@ double db_layout = 2.3;
|
||||||
|
|
||||||
int db_upgrade(d_char **error);
|
int db_upgrade(d_char **error);
|
||||||
|
|
||||||
int srv_open(char *basedir)
|
int srv_open(char *basedir, int auto_upgrade)
|
||||||
/* opens a server */
|
/* opens a server */
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -69,7 +69,14 @@ int srv_open(char *basedir)
|
||||||
error = xs_fmt("DEBUG level set to %d from environment", dbglevel);
|
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("Commands:\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("init [{basedir}] Initializes the database\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("adduser {basedir} [{uid}] Adds a new user\n");
|
||||||
printf("httpd {basedir} Starts the HTTPD daemon\n");
|
printf("httpd {basedir} Starts the HTTPD daemon\n");
|
||||||
printf("purge {basedir} Purges old data\n");
|
printf("purge {basedir} Purges old data\n");
|
||||||
|
@ -76,6 +77,19 @@ int main(int argc, char *argv[])
|
||||||
return initdb(basedir);
|
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) {
|
if (strcmp(cmd, "markdown") == 0) {
|
||||||
/* undocumented, for testing only */
|
/* undocumented, for testing only */
|
||||||
xs *c = xs_readall(stdin);
|
xs *c = xs_readall(stdin);
|
||||||
|
@ -88,7 +102,7 @@ int main(int argc, char *argv[])
|
||||||
if ((basedir = GET_ARGV()) == NULL)
|
if ((basedir = GET_ARGV()) == NULL)
|
||||||
return usage();
|
return usage();
|
||||||
|
|
||||||
if (!srv_open(basedir)) {
|
if (!srv_open(basedir, 0)) {
|
||||||
srv_log(xs_fmt("error opening database at %s", basedir));
|
srv_log(xs_fmt("error opening database at %s", basedir));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
2
snac.h
2
snac.h
|
@ -24,7 +24,7 @@ double ftime(void);
|
||||||
void srv_debug(int level, d_char *str);
|
void srv_debug(int level, d_char *str);
|
||||||
#define srv_log(str) srv_debug(0, str)
|
#define srv_log(str) srv_debug(0, str)
|
||||||
|
|
||||||
int srv_open(char *basedir);
|
int srv_open(char *basedir, int auto_upgrade);
|
||||||
void srv_free(void);
|
void srv_free(void);
|
||||||
|
|
||||||
typedef struct _snac {
|
typedef struct _snac {
|
||||||
|
|
Loading…
Reference in a new issue