Archived
1
0
Fork 0

fix: supports old sqlite version in downgrade

This commit is contained in:
Dmitriy Pleshevskiy 2021-05-17 10:51:53 +03:00
parent 97178fcb02
commit c20f3c3411
4 changed files with 18 additions and 11 deletions

3
.gitignore vendored
View file

@ -1,2 +1,5 @@
target/
Cargo.lock
# sqlite databases
*.db

View file

@ -12,8 +12,6 @@ pub(crate) fn apply_sql(app: &App, cmd_opts: ApplyCommandOpt) -> StdResult<()> {
let migration_manager = MigrationManager::from(&config);
println!("here");
let file_contents = cmd_opts
.file_paths
.clone()
@ -35,7 +33,6 @@ pub(crate) fn apply_sql(app: &App, cmd_opts: ApplyCommandOpt) -> StdResult<()> {
file_contents
.iter()
.try_for_each(|content| {
println!("{}", &content);
maybe_with_transaction(
!cmd_opts.transaction_opts.single_transaction,
conn,

View file

@ -476,7 +476,7 @@ mod upgrade {
inner("sqlite", || {
use rusqlite::Connection;
let conn = Connection::open_in_memory()?;
let conn = Connection::open(SQLITE_URL)?;
let res =
conn.execute_batch("SELECT p.id, a.id FROM persons AS p, articles AS a")?;
assert_eq!(res, ());
@ -682,7 +682,6 @@ mod apply {
#[cfg(any(feature = "sqlite", feature = "rusqlite"))]
remove_sqlite_db().and_then(|_| {
println!("upgrade");
inner(
"sqlite",
vec![
@ -692,8 +691,7 @@ mod apply {
|| {
use rusqlite::Connection;
let conn = Connection::open_in_memory()?;
println!("upgraded?");
let conn = Connection::open(SQLITE_URL)?;
let res =
conn.execute_batch("SELECT p.id, a.id FROM persons AS p, articles AS a")?;
assert_eq!(res, ());
@ -702,7 +700,6 @@ mod apply {
},
)?;
println!("downgrade");
inner(
"sqlite",
vec![
@ -712,7 +709,7 @@ mod apply {
|| {
use rusqlite::Connection;
let conn = Connection::open_in_memory()?;
let conn = Connection::open(SQLITE_URL)?;
let res =
conn.execute_batch("SELECT p.id, a.id FROM persons AS p, articles AS a");
assert!(res.is_err());

View file

@ -1,6 +1,16 @@
-- This file should undo anything in `up.sql`
ALTER TABLE articles
DROP COLUMN author_person_id;
CREATE TABLE tmp_articles (
id int AUTO_INCREMENT PRIMARY KEY,
title text NOT NULL CHECK (length(title) > 0),
content text NOT NULL,
created_at timestamp NOT NULL DEFAULT current_timestamp
);
INSERT INTO tmp_articles (id, title, content, created_at)
SELECT id, title, content, created_at FROM articles;
DROP TABLE articles;
ALTER TABLE tmp_articles RENAME TO articles;
DROP TABLE persons;