Going somewhere.

This commit is contained in:
didier amyot committed 2022-12-05 09:44:05 -05:00
1 parent fc13cf7f99
commit 3dc963cdea
5 files changed
+63 -62

No files matched your search

+3 -38
View File
@@ -1,6 +1,6 @@
use rusqlite::{Connection, Transaction};
use sha2::{Digest, Sha256, Sha512};
use sha2::{Digest, Sha256};
const INITIAL_MIGRATION: &str = "
CREATE TABLE IF NOT EXISTS shitty_migrations (
@@ -9,42 +9,6 @@ CREATE TABLE IF NOT EXISTS shitty_migrations (
);
";
const MIGRATION_SCRIPT: &str = "
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
public_key TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS security_types (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL UNIQUE
);
CREATE TABLE IF NOT EXISTS securities (
id INTEGER PRIMARY KEY AUTOINCREMENT,
security_type INTEGER NOT NULL,
name TEXT NOT NULL UNIQUE,
symbol TEXT NOT NULL UNIQUE,
FOREIGN KEY(security_type) REFERENCES security_types(id)
);
//
// CREATE TABLE IF NOT EXISTS account(
// id INTEGER PRIMARY KEY AUTOINCREMENT,
// security INTEGER NOT NULL,
// owner INTEGER NOT NULL,
//
// FOREIGN KEY(security) REFERENCES securities(id)
// );
//
// CREATE TABLE IF NOT EXISTS account_values(
// id INTEGER PRIMARY KEY AUTOINCREMENT
// );
";
fn get_id_of_new_migration(tx: &Transaction) -> usize {
let q = "SELECT COALESCE(MAX(id) + 1, 0) FROM shitty_migrations";
return tx.query_row(q, (), |row| row.get::<usize, usize>(0)).unwrap();
@@ -80,7 +44,7 @@ fn compute_migration_sha256(migration: &String) -> String {
return format!("{:x}", ret);
}
fn check_migration(tx: &Transaction, id: usize, migration: &String) -> Result<String, io::Error> {
fn check_migration(tx: &Transaction, id: usize, migration: &String) {
let q = "SELECT sha256 FROM shitty_migrations WHERE id = ?1";
let res = tx.query_row(q, (&id, ), |row| row.get::<usize, String>(0)).unwrap();
let expected = compute_migration_sha256(migration);
@@ -130,6 +94,7 @@ mod test {
assert_eq!(c, c);
}
#[ignore]
#[test]
fn broken_migration() {
let mut conn = Connection::open_in_memory().unwrap();