mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-26 12:49:24 -05:00
Create the column nullable
There's no real point in ever making the column non-nullable, and doing so breaks the sytests.
This commit is contained in:
parent
5c1d301fd9
commit
51d7df1915
@ -60,6 +60,10 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def run_create(cur, database_engine, *args, **kwargs):
|
def run_create(cur, database_engine, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def run_upgrade(cur, database_engine, *args, **kwargs):
|
||||||
if isinstance(database_engine, PostgresEngine):
|
if isinstance(database_engine, PostgresEngine):
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
ALTER TABLE events ALTER COLUMN content DROP NOT NULL;
|
ALTER TABLE events ALTER COLUMN content DROP NOT NULL;
|
||||||
@ -67,27 +71,22 @@ def run_create(cur, database_engine, *args, **kwargs):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# sqlite is an arse about this. ref: https://www.sqlite.org/lang_altertable.html
|
# sqlite is an arse about this. ref: https://www.sqlite.org/lang_altertable.html
|
||||||
cur.execute("PRAGMA schema_version")
|
|
||||||
(oldver,) = cur.fetchone()
|
|
||||||
|
|
||||||
cur.execute("SELECT sql FROM sqlite_master WHERE tbl_name='events' AND type='table'")
|
cur.execute("SELECT sql FROM sqlite_master WHERE tbl_name='events' AND type='table'")
|
||||||
(oldsql,) = cur.fetchone()
|
(oldsql,) = cur.fetchone()
|
||||||
|
|
||||||
sql = oldsql.replace("content TEXT NOT NULL", "content TEXT")
|
sql = oldsql.replace("content TEXT NOT NULL", "content TEXT")
|
||||||
if sql == oldsql:
|
if sql == oldsql:
|
||||||
raise Exception("Couldn't find null constraint to drop in %s" % oldsql)
|
raise Exception("Couldn't find null constraint to drop in %s" % oldsql)
|
||||||
|
|
||||||
logger.info("Replacing definition of 'events' with: %s", sql)
|
logger.info("Replacing definition of 'events' with: %s", sql)
|
||||||
|
|
||||||
|
cur.execute("PRAGMA schema_version")
|
||||||
|
(oldver,) = cur.fetchone()
|
||||||
cur.execute("PRAGMA writable_schema=ON")
|
cur.execute("PRAGMA writable_schema=ON")
|
||||||
|
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"UPDATE sqlite_master SET sql=? WHERE tbl_name='events' AND type='table'",
|
"UPDATE sqlite_master SET sql=? WHERE tbl_name='events' AND type='table'",
|
||||||
(sql, ),
|
(sql, ),
|
||||||
)
|
)
|
||||||
|
|
||||||
cur.execute("PRAGMA schema_version=%i" % (oldver+1,))
|
cur.execute("PRAGMA schema_version=%i" % (oldver+1,))
|
||||||
cur.execute("PRAGMA writable_schema=OFF")
|
cur.execute("PRAGMA writable_schema=OFF")
|
||||||
|
|
||||||
|
|
||||||
def run_upgrade(*args, **kwargs):
|
|
||||||
pass
|
|
||||||
|
@ -19,7 +19,12 @@ CREATE TABLE IF NOT EXISTS events(
|
|||||||
event_id TEXT NOT NULL,
|
event_id TEXT NOT NULL,
|
||||||
type TEXT NOT NULL,
|
type TEXT NOT NULL,
|
||||||
room_id TEXT NOT NULL,
|
room_id TEXT NOT NULL,
|
||||||
content TEXT NOT NULL,
|
|
||||||
|
-- 'content' used to be created NULLable, but as of delta 50 we drop that constraint.
|
||||||
|
-- the hack we use to drop the constraint doesn't work for an in-memory sqlite
|
||||||
|
-- database, which breaks the sytests. Hence, we no longer make it nullable.
|
||||||
|
content TEXT,
|
||||||
|
|
||||||
unrecognized_keys TEXT,
|
unrecognized_keys TEXT,
|
||||||
processed BOOL NOT NULL,
|
processed BOOL NOT NULL,
|
||||||
outlier BOOL NOT NULL,
|
outlier BOOL NOT NULL,
|
||||||
|
Loading…
Reference in New Issue
Block a user