How to restore a deleted (focal)board or playbook

hi there,

my assumption was, that since version 6 boards and playbooks are part of the base mattermost.
Thus i thought it should be possible to restore deleted boards or playbooks like i can do with teams and channels (with mmctl).
Turns out, I can not.
Also there is no documentation about that.

So my question is - how do i undelete a deleted board?

some info:
enterprise version of 7.7.1 with postgres as the database

Hi @mdc_decker ,

the integration is happening in multiple stages and it is far from being complete. mmctl is just a command line API client, if you like, which would need to be extended for boards and playbooks features in the future and that’s not on the roadmap as of yet due to more important things that need to be done for those two new additions to the Mattermost suite.

Boards do only get soft-deleted, so it should be possible to restore it directly in the database. The attribute which gets changed is usually the deleteat attribute, which is 0 by default (indicating that no deletion has happened) and will be set to the timestamp when the item has been deleted.
Changing the relevant entries back to have a deleteat timestamp of 0 will undelete the boards.

if it would be that easy …

first: its “delete_at”
second: the record is being moved (why in the hell …) to another table

so here is what i did so far

mattermost=# select title,delete_at from focalboard_boards where title like 'blub%';
 title | delete_at
-------+-----------
(0 rows)
mattermost=# select title,delete_at,id from focalboard_boards_history where title like 'blub%';
   title    |   delete_at   |             id
------------+---------------+-----------------------------
 blub board |             0 | bzimxi419bjnjbp7ru7eeuwdeno
 blub board | 1676899974594 | bzimxi419bjnjbp7ru7eeuwdeno
(2 rows)
mattermost=# insert into focalboard_boards select * from focalboard_boards_history where id='bzimxi419bjnjbp7ru7eeuwdeno' and delete_at = '1676899974594';
INSERT 0 1
mattermost=# update focalboard_boards set delete_at=0 where id='bzimxi419bjnjbp7ru7eeuwdeno';
UPDATE 1

after those steps - the board can be found again in the “find boards” but selecting it turns out with “Sorry, something went wrong. Board not found”

clearly there are missing steps - which one?

I think you do also need to take the blocks tables into account. Blocks are part of a board, so when you restore the board but not the blocks, it will be empty (or broken), so please check the blocks_history table and look for blocks related to your boardid and restore them to the blocks table like you did with the boards table.

i tried - but it always gives me this error

mattermost=# select title,delete_at,id,board_id from focalboard_blocks_history where delete_at = '1676899974596' ;
   title    |   delete_at   |             id              |          board_id
------------+---------------+-----------------------------+-----------------------------
 asd        | 1676899974596 | chde3i1otm7r55ygfz1wroqz8zc | bzimxi419bjnjbp7ru7eeuwdeno
 Board view | 1676899974596 | vgzwfyy5w33bytkie6tuszrkkxo | bzimxi419bjnjbp7ru7eeuwdeno
 card2      | 1676899974596 | cs3r9oi6dh3n83kjfck3ex8mn3e | bzimxi419bjnjbp7ru7eeuwdeno
(3 rows)
mattermost=# insert into focalboard_blocks select * from focalboard_blocks_history where id = 'chde3i1otm7r55ygfz1wroqz8zc';
ERROR:  duplicate key value violates unique constraint "focalboard_blocks_pkey1"
DETAIL:  Key (id)=(chde3i1otm7r55ygfz1wroqz8zc) already exists.

no rows in the target table

mattermost=# select title,delete_at,id from focalboard_blocks where id = 'chde3i1otm7r55ygfz1wroqz8zc' ;
 title | delete_at | id
-------+-----------+----
(0 rows)

okay lets have a look at duplicate rows

mattermost=# select title,delete_at,id from focalboard_blocks_history where id = 'chde3i1otm7r55ygfz1wroqz8zc' ;
 title |   delete_at   |             id
-------+---------------+-----------------------------
       |             0 | chde3i1otm7r55ygfz1wroqz8zc
 asd   |             0 | chde3i1otm7r55ygfz1wroqz8zc
 asd   |             0 | chde3i1otm7r55ygfz1wroqz8zc
 asd   | 1676899974596 | chde3i1otm7r55ygfz1wroqz8zc
(4 rows)

okay - only inserting one row

mattermost=# insert into focalboard_blocks select * from focalboard_blocks_history where id = 'chde3i1otm7r55ygfz1wroqz8zc' and delete_at = '1676899974596';
ERROR:  null value in column "channel_id" violates not-null constraint
DETAIL:  Failing row contains (chde3i1otm7r55ygfz1wroqz8zc, 2023-02-20 14:32:54.594469+01, bzimxi419bjnjbp7ru7eeuwdeno, 1, card, asd, {"contentOrder":[],"icon":"💶","isTemplate":false,"properties"..., 1676899456123, 1676899974596, 1676899974596, null, th19r78njpfgub1771m88mshge, null, th19r78njpfgub1771m88mshge, bzimxi419bjnjbp7ru7eeuwdeno).

i am confused …

it looks like “resetting” the channel_id to 0 beforehand works

update focalboard_blocks_history set channel_id=0 where board_id='bzimxi419bjnjbp7ru7eeuwdeno' and delete_at = '1676899974596';

can you confirm that this is the way to restore a board?

I found an older topic where I walked another user through that - not sure if this method still works, let me know if it did:

for anybody else facing this problem - here is what i have done

find the missing boards id in “focalboard_boards_history” - look for “delete_at”

fire those statements - replace “board_id” and “delete_at”

insert into focalboard_boards select * from focalboard_boards_history where id='bwh84gmi847ya3yabocoui9zk6w' and delete_at = '1676892081577';
update focalboard_boards set delete_at=0 where id='bwh84gmi847ya3yabocoui9zk6w';

update focalboard_blocks_history set channel_id=0 where board_id='bwh84gmi847ya3yabocoui9zk6w' and delete_at > 1676892081577;

insert into focalboard_blocks select * from focalboard_blocks_history where board_id='bwh84gmi847ya3yabocoui9zk6w' and delete_at > 1676892081577;
update focalboard_blocks set delete_at=0 where board_id='bwh84gmi847ya3yabocoui9zk6w' and delete_at > 1676892081577;