1
0
Fork 0
mirror of https://github.com/processone/ejabberd synced 2025-10-03 09:49:18 +02:00

Update code for switching to new schema type to users table changes

This commit is contained in:
Paweł Chmielowski 2025-05-12 18:47:18 +02:00
parent 128103b7b2
commit d65cafae64
2 changed files with 4 additions and 3 deletions

View file

@ -20,7 +20,7 @@
-- ALTER TABLE users ADD COLUMN server_host text NOT NULL DEFAULT '<HOST>';
-- ALTER TABLE users DROP CONSTRAINT users_pkey;
-- ALTER TABLE users ADD PRIMARY KEY (server_host, username);
-- ALTER TABLE users ADD PRIMARY KEY (server_host, username, "type");
-- ALTER TABLE users ALTER COLUMN server_host DROP DEFAULT;
-- ALTER TABLE last ADD COLUMN server_host text NOT NULL DEFAULT '<HOST>';

View file

@ -130,7 +130,7 @@ update_tables(State) ->
case add_sh_column(State, "users") of
true ->
drop_pkey(State, "users"),
add_pkey(State, "users", ["server_host", "username"]),
add_pkey(State, "users", ["server_host", "username", "type"]),
drop_sh_default(State, "users");
false ->
ok
@ -443,7 +443,8 @@ drop_pkey(#state{dbtype = mysql} = State, Table) ->
["ALTER TABLE ", Table, " DROP PRIMARY KEY;"]).
add_pkey(#state{dbtype = pgsql} = State, Table, Cols) ->
SCols = string:join(Cols, ", "),
Cols2 = lists:map(fun("type") -> "\"type\""; (V) -> V end, Cols),
SCols = string:join(Cols2, ", "),
sql_query(
State#state.host,
["ALTER TABLE ", Table, " ADD PRIMARY KEY (", SCols, ");"]);