Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Create a new full schema snapshot #13715

Closed
erikjohnston opened this issue Sep 5, 2022 · 8 comments · Fixed by #13873
Closed

Create a new full schema snapshot #13715

erikjohnston opened this issue Sep 5, 2022 · 8 comments · Fixed by #13873
Assignees
Labels
A-Testing Issues related to testing in complement, synapse, etc O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Blocks non-critical functionality, workarounds exist. T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. Z-Dev-Wishlist Makes developers' lives better, but doesn't have direct user impact

Comments

@erikjohnston
Copy link
Member

If nothing else, this will speed up the unit tests quite a lot.

There is a scripts-dev/make_full_schema.sh script that sort of half works ish. The challenges are:

  1. We have to handle the fact there are two different sets of schemas, "main" and "state".
  2. There are also some tables that exist on all DBs (e.g. schema_version table)
@squahtx squahtx added S-Minor Blocks non-critical functionality, workarounds exist. T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. O-Uncommon Most users are unlikely to come across this or unexpected workflow A-Testing Issues related to testing in complement, synapse, etc labels Sep 5, 2022
@DMRobertson DMRobertson self-assigned this Sep 6, 2022
@DMRobertson
Copy link
Contributor

I would like to try and simplify the make_full_schema script as I do this. My current objections:

  • We use portdb to port the sqlite schema onto postgres, meaning that any postgres-specific deltas might not be represented in the new postgres schema? (I don't trust portdb.)
  • We have to manually omit sqlite's full text search extra tables (_content, _segments, _segdir, _docsize, _stat)
  • We also have to manually omit the schema metadata tables schema_version, applied_schema_deltas, applied_module_schemas
  • The generated output from sqlite requires some manual tidy-up.
  • Unclear how to handle the main and state schemas.

@DMRobertson
Copy link
Contributor

DMRobertson commented Sep 9, 2022

We can generate a tidier schema using sqlite's .schema instead of .dump. But doing so omits various INSERT INTO statements:

$ scripts-dev/make_full_schema.sh -o dump2 -p synapse_user
[...]
$ grep "INSERT INTO" dump2/full.sql.sqlite 
INSERT INTO schema_compat_version VALUES('X',72);
INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql)VALUES('table','event_search','event_search',0,'CREATE VIRTUAL TABLE event_search USING fts4 ( event_id, room_id, sender, key, value )');
INSERT INTO appservice_stream_position VALUES('X',0);
INSERT INTO federation_stream_position VALUES('federation',-1,'master');
INSERT INTO federation_stream_position VALUES('events',-1,'master');
INSERT INTO event_push_summary_stream_ordering VALUES('X',0);
INSERT INTO user_directory_stream_pos VALUES('X',1);
INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql)VALUES('table','user_directory_search','user_directory_search',0,'CREATE VIRTUAL TABLE user_directory_search USING fts4 ( user_id, value )');
INSERT INTO stats_incremental_position VALUES('X',1);
INSERT INTO event_push_summary_last_receipt_stream_id VALUES('X',0);

If Synapse uses upserts to populate these rows, then there is no need to include inserts in the schema, and I can use .schema to make the process of taking a schema dump more automatic.

@DMRobertson
Copy link
Contributor

If [...] I can use .schema to make the process of taking a schema dump more automatic.

On reflection I think I should suck it up and leave the dump as it is, lest we reintroduce #6311.

@richvdh
Copy link
Member

richvdh commented Sep 14, 2022

@DMRobertson are you actively working on this? I've got most of a rewrite of make_full_schema which I think will work.

@clokep
Copy link
Member

clokep commented Sep 14, 2022

@DMRobertson are you actively working on this? I've got most of a rewrite of make_full_schema which I think will work.

I believe #13770, #13788, #13792, and #13808 are related to this.

@richvdh
Copy link
Member

richvdh commented Sep 14, 2022

ah, thanks. Sorry, I should have said something sooner.

@DMRobertson
Copy link
Contributor

@DMRobertson are you actively working on this? I've got most of a rewrite of make_full_schema which I think will work.

I believe #13770, #13788, #13792, and #13808 are related to this.

That's right. #13792 is the most interesting of those. I wasn't planning to do anything more on making a snapshot before of the above reviews and before @clokep and @MadLittleMods get their upcoming database changes into a stableish state.

@DMRobertson DMRobertson added the Z-Dev-Wishlist Makes developers' lives better, but doesn't have direct user impact label Sep 23, 2022
@DMRobertson
Copy link
Contributor

#13873 has

  • additional fixes to the schema dump script
  • Synapse changes which ingest SQL directly (avoiding problems where our hand-written parser(!?) cannot handle trigger definitions
  • The actual dumps

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Testing Issues related to testing in complement, synapse, etc O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Blocks non-critical functionality, workarounds exist. T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. Z-Dev-Wishlist Makes developers' lives better, but doesn't have direct user impact
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants