|
29 | 29 | MultiWriterIdGenerator,
|
30 | 30 | StreamIdGenerator,
|
31 | 31 | )
|
| 32 | +from synapse.types import get_domain_from_id |
32 | 33 | from synapse.util.caches.stream_change_cache import StreamChangeCache
|
33 | 34 |
|
34 | 35 | from .account_data import AccountDataStore
|
@@ -591,22 +592,24 @@ def check_database_before_upgrade(cur, database_engine, config: HomeServerConfig
|
591 | 592 | """Called before upgrading an existing database to check that it is broadly sane
|
592 | 593 | compared with the configuration.
|
593 | 594 | """
|
594 |
| - logger.info("Running sanity-checks on database...") |
595 |
| - domain = config.server_name |
| 595 | + logger.info("Checking database for consistency with configuration...") |
596 | 596 |
|
597 |
| - sql = database_engine.convert_param_style( |
598 |
| - "SELECT COUNT(*) FROM users WHERE name NOT LIKE ?" |
599 |
| - ) |
600 |
| - pat = "%:" + domain |
601 |
| - cur.execute(sql, (pat,)) |
602 |
| - num_not_matching = cur.fetchall()[0][0] |
603 |
| - if num_not_matching == 0: |
| 597 | + # if there are any users in the database, check that the username matches our |
| 598 | + # configured server name. |
| 599 | + |
| 600 | + cur.execute("SELECT name FROM users LIMIT 1") |
| 601 | + rows = cur.fetchall() |
| 602 | + if not rows: |
| 603 | + return |
| 604 | + |
| 605 | + user_domain = get_domain_from_id(rows[0][0]) |
| 606 | + if user_domain == config.server_name: |
604 | 607 | return
|
605 | 608 |
|
606 | 609 | raise Exception(
|
607 | 610 | "Found users in database not native to %s!\n"
|
608 |
| - "You cannot changed a synapse server_name after it's been configured" |
609 |
| - % (domain,) |
| 611 | + "You cannot change a synapse server_name after it's been configured" |
| 612 | + % (config.server_name,) |
610 | 613 | )
|
611 | 614 |
|
612 | 615 |
|
|
0 commit comments