My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/development/libs/barrel/src/tests/sqlite3/create_table.rs

37 lines
1.7 KiB

//! Some unit tests that create create tables
#![allow(unused_imports)]
use crate::backend::{SqlGenerator, Sqlite};
use crate::{types, Migration, Table};
#[test]
fn create_multiple_tables() {
let mut m = Migration::new();
m.create_table("artist", |t| {
t.add_column("id", types::primary());
t.add_column("name", types::text().nullable(true));
t.add_column("description", types::text().nullable(true));
t.add_column("pic", types::text().nullable(true));
t.add_column("mbid", types::text().nullable(true));
});
m.create_table("album", |t| {
t.add_column("id", types::primary());
t.add_column("name", types::text().nullable(true));
t.add_column("pic", types::text().nullable(true));
t.add_column("mbid", types::text().nullable(true));
});
assert_eq!(m.make::<Sqlite>(), String::from("CREATE TABLE \"artist\" (\"id\" INTEGER NOT NULL PRIMARY KEY, \"name\" TEXT, \"description\" TEXT, \"pic\" TEXT, \"mbid\" TEXT);CREATE TABLE \"album\" (\"id\" INTEGER NOT NULL PRIMARY KEY, \"name\" TEXT, \"pic\" TEXT, \"mbid\" TEXT);"));
}
#[test]
fn create_table_if_not_exists_doesnt_hit_unreachable() {
let mut m = Migration::new();
m.create_table_if_not_exists("artist", |t| {
t.add_column("id", types::primary());
t.add_column("name", types::text().nullable(true));
t.add_column("description", types::text().nullable(true));
t.add_column("pic", types::text().nullable(true));
t.add_column("mbid", types::text().nullable(true));
});
assert_eq!(m.make::<Sqlite>(), String::from("CREATE TABLE IF NOT EXISTS \"artist\" (\"id\" INTEGER NOT NULL PRIMARY KEY, \"name\" TEXT, \"description\" TEXT, \"pic\" TEXT, \"mbid\" TEXT);"));
}