Store room times as epoch time
Resets migrations because nobody except me is using cove anyways and this is easier than keeping backwards compatibility.
This commit is contained in:
parent
cbe2b2e10e
commit
b57c70dd01
3 changed files with 13 additions and 18 deletions
|
|
@ -86,7 +86,7 @@ impl EuphVault {
|
|||
&self.room
|
||||
}
|
||||
|
||||
pub fn join(&self, time: OffsetDateTime) {
|
||||
pub fn join(&self, time: Time) {
|
||||
let request = EuphRequest::Join {
|
||||
room: self.room.clone(),
|
||||
time,
|
||||
|
|
@ -221,7 +221,7 @@ pub(super) enum EuphRequest {
|
|||
},
|
||||
Join {
|
||||
room: String,
|
||||
time: OffsetDateTime,
|
||||
time: Time,
|
||||
},
|
||||
Delete {
|
||||
room: String,
|
||||
|
|
@ -382,7 +382,7 @@ impl EuphRequest {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn join(conn: &mut Connection, room: String, time: OffsetDateTime) -> rusqlite::Result<()> {
|
||||
fn join(conn: &mut Connection, room: String, time: Time) -> rusqlite::Result<()> {
|
||||
conn.execute(
|
||||
"
|
||||
INSERT INTO euph_rooms (room, first_joined, last_joined)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ pub fn migrate(conn: &mut Connection) -> rusqlite::Result<()> {
|
|||
tx.query_row("SELECT * FROM pragma_user_version", [], |r| r.get(0))?;
|
||||
|
||||
let total = MIGRATIONS.len();
|
||||
assert!(user_version <= total, "malformed database schema");
|
||||
for (i, migration) in MIGRATIONS.iter().enumerate().skip(user_version) {
|
||||
println!("Migrating vault from {} to {} (out of {})", i, i + 1, total);
|
||||
migration(&mut tx)?;
|
||||
|
|
@ -16,15 +17,15 @@ pub fn migrate(conn: &mut Connection) -> rusqlite::Result<()> {
|
|||
tx.commit()
|
||||
}
|
||||
|
||||
const MIGRATIONS: [fn(&mut Transaction<'_>) -> rusqlite::Result<()>; 2] = [m1, m2];
|
||||
const MIGRATIONS: [fn(&mut Transaction<'_>) -> rusqlite::Result<()>; 1] = [m1];
|
||||
|
||||
fn m1(tx: &mut Transaction<'_>) -> rusqlite::Result<()> {
|
||||
tx.execute_batch(
|
||||
"
|
||||
CREATE TABLE euph_rooms (
|
||||
room TEXT NOT NULL PRIMARY KEY,
|
||||
first_joined TEXT NOT NULL,
|
||||
last_joined TEXT NOT NULL
|
||||
first_joined INT NOT NULL,
|
||||
last_joined INT NOT NULL
|
||||
) STRICT;
|
||||
|
||||
CREATE TABLE euph_msgs (
|
||||
|
|
@ -67,6 +68,10 @@ fn m1(tx: &mut Transaction<'_>) -> rusqlite::Result<()> {
|
|||
CHECK (start IS NULL OR end IS NOT NULL)
|
||||
) STRICT;
|
||||
|
||||
CREATE TABLE euph_cookies (
|
||||
cookie TEXT NOT NULL
|
||||
) STRICT;
|
||||
|
||||
CREATE INDEX euph_idx_msgs_room_id_parent
|
||||
ON euph_msgs (room, id, parent);
|
||||
|
||||
|
|
@ -75,13 +80,3 @@ fn m1(tx: &mut Transaction<'_>) -> rusqlite::Result<()> {
|
|||
",
|
||||
)
|
||||
}
|
||||
|
||||
fn m2(tx: &mut Transaction<'_>) -> rusqlite::Result<()> {
|
||||
tx.execute_batch(
|
||||
"
|
||||
CREATE TABLE euph_cookies (
|
||||
cookie TEXT NOT NULL
|
||||
) STRICT;
|
||||
",
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue