mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Edit SQL schema to use string IDs not ints. Use token as ID. Update tests.
This commit is contained in:
parent
b59aa74556
commit
c217504949
@ -231,7 +231,8 @@ class ApplicationServiceStore(SQLBaseStore):
|
|||||||
url=as_info["url"],
|
url=as_info["url"],
|
||||||
namespaces=as_info["namespaces"],
|
namespaces=as_info["namespaces"],
|
||||||
hs_token=as_info["hs_token"],
|
hs_token=as_info["hs_token"],
|
||||||
sender=as_info["sender"]
|
sender=as_info["sender"],
|
||||||
|
id=as_info["as_token"] # the token is the only unique thing here
|
||||||
)
|
)
|
||||||
|
|
||||||
def _populate_appservice_cache(self, config_files):
|
def _populate_appservice_cache(self, config_files):
|
||||||
@ -268,16 +269,20 @@ class ApplicationServiceTransactionStore(SQLBaseStore):
|
|||||||
A Deferred which resolves to a list of ApplicationServices, which
|
A Deferred which resolves to a list of ApplicationServices, which
|
||||||
may be empty.
|
may be empty.
|
||||||
"""
|
"""
|
||||||
sql = (
|
results = yield self._simple_select_list(
|
||||||
"SELECT r.*, a.* FROM application_services_state AS s LEFT JOIN"
|
"application_services_state",
|
||||||
" application_services AS a ON a.id=s.as_id LEFT JOIN"
|
dict(state=state),
|
||||||
" application_services_regex AS r ON r.as_id=a.id WHERE state = ?"
|
["as_id"]
|
||||||
)
|
|
||||||
results = yield self._execute_and_decode(
|
|
||||||
"get_appservices_by_state", sql, state
|
|
||||||
)
|
)
|
||||||
# NB: This assumes this class is linked with ApplicationServiceStore
|
# NB: This assumes this class is linked with ApplicationServiceStore
|
||||||
defer.returnValue(self._parse_services_dict(results))
|
as_list = yield self.get_app_services()
|
||||||
|
services = []
|
||||||
|
|
||||||
|
for res in results:
|
||||||
|
for service in as_list:
|
||||||
|
if service.id == res["as_id"]:
|
||||||
|
services.append(service)
|
||||||
|
defer.returnValue(services)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_appservice_state(self, service):
|
def get_appservice_state(self, service):
|
||||||
|
@ -14,14 +14,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS application_services_state(
|
CREATE TABLE IF NOT EXISTS application_services_state(
|
||||||
as_id INTEGER PRIMARY KEY,
|
as_id TEXT PRIMARY KEY,
|
||||||
state TEXT,
|
state TEXT,
|
||||||
last_txn TEXT,
|
last_txn TEXT
|
||||||
FOREIGN KEY(as_id) REFERENCES application_services(id)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS application_services_txns(
|
CREATE TABLE IF NOT EXISTS application_services_txns(
|
||||||
as_id INTEGER NOT NULL,
|
as_id TEXT NOT NULL,
|
||||||
txn_id INTEGER NOT NULL,
|
txn_id INTEGER NOT NULL,
|
||||||
event_ids TEXT NOT NULL,
|
event_ids TEXT NOT NULL,
|
||||||
UNIQUE(as_id, txn_id) ON CONFLICT ROLLBACK
|
UNIQUE(as_id, txn_id) ON CONFLICT ROLLBACK
|
||||||
|
@ -101,42 +101,48 @@ class ApplicationServiceTransactionStoreTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
self.as_yaml_files = []
|
||||||
self.db_pool = SQLiteMemoryDbPool()
|
self.db_pool = SQLiteMemoryDbPool()
|
||||||
yield self.db_pool.prepare()
|
yield self.db_pool.prepare()
|
||||||
hs = HomeServer(
|
|
||||||
"test", db_pool=self.db_pool, clock=MockClock(), config=Mock()
|
|
||||||
)
|
|
||||||
self.as_list = [
|
self.as_list = [
|
||||||
{
|
{
|
||||||
"token": "token1",
|
"token": "token1",
|
||||||
"url": "https://matrix-as.org",
|
"url": "https://matrix-as.org",
|
||||||
"id": 3
|
"id": "token1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"token": "alpha_tok",
|
"token": "alpha_tok",
|
||||||
"url": "https://alpha.com",
|
"url": "https://alpha.com",
|
||||||
"id": 5
|
"id": "alpha_tok"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"token": "beta_tok",
|
"token": "beta_tok",
|
||||||
"url": "https://beta.com",
|
"url": "https://beta.com",
|
||||||
"id": 6
|
"id": "beta_tok"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"token": "delta_tok",
|
"token": "delta_tok",
|
||||||
"url": "https://delta.com",
|
"url": "https://delta.com",
|
||||||
"id": 7
|
"id": "delta_tok"
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
for s in self.as_list:
|
for s in self.as_list:
|
||||||
yield self._add_service(s["id"], s["url"], s["token"])
|
yield self._add_service(s["url"], s["token"])
|
||||||
|
|
||||||
|
hs = HomeServer(
|
||||||
|
"test", db_pool=self.db_pool, clock=MockClock(), config=Mock(
|
||||||
|
app_service_config_files=self.as_yaml_files
|
||||||
|
)
|
||||||
|
)
|
||||||
self.store = TestTransactionStore(hs)
|
self.store = TestTransactionStore(hs)
|
||||||
|
|
||||||
def _add_service(self, as_id, url, token):
|
def _add_service(self, url, as_token):
|
||||||
return self.db_pool.runQuery(
|
as_yaml = dict(url=url, as_token=as_token, hs_token="something",
|
||||||
"INSERT INTO application_services(id, url, token) VALUES(?,?,?)",
|
sender="a_sender", namespaces={})
|
||||||
(as_id, url, token)
|
# use the token as the filename
|
||||||
)
|
with open(as_token, 'w') as outfile:
|
||||||
|
outfile.write(yaml.dump(as_yaml))
|
||||||
|
self.as_yaml_files.append(as_token)
|
||||||
|
|
||||||
def _set_state(self, id, state, txn=None):
|
def _set_state(self, id, state, txn=None):
|
||||||
return self.db_pool.runQuery(
|
return self.db_pool.runQuery(
|
||||||
@ -388,8 +394,10 @@ class ApplicationServiceTransactionStoreTestCase(unittest.TestCase):
|
|||||||
ApplicationServiceState.DOWN
|
ApplicationServiceState.DOWN
|
||||||
)
|
)
|
||||||
self.assertEquals(2, len(services))
|
self.assertEquals(2, len(services))
|
||||||
self.assertEquals(self.as_list[2]["id"], services[0].id)
|
self.assertEquals(
|
||||||
self.assertEquals(self.as_list[0]["id"], services[1].id)
|
set([self.as_list[2]["id"], self.as_list[0]["id"]]),
|
||||||
|
set([services[0].id, services[1].id])
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# required for ApplicationServiceTransactionStoreTestCase tests
|
# required for ApplicationServiceTransactionStoreTestCase tests
|
||||||
|
Loading…
Reference in New Issue
Block a user