diff --git a/db/migrations/2019-04-26-020705_fix_note_constraint/down.sql b/db/migrations/2019-04-26-020705_fix_note_constraint/down.sql new file mode 100644 index 00000000..4d2dfdb5 --- /dev/null +++ b/db/migrations/2019-04-26-020705_fix_note_constraint/down.sql @@ -0,0 +1,3 @@ +ALTER TABLE notes + DROP CONSTRAINT notes_title_user_id_parent_note_id, + ADD CONSTRAINT notes_title_id_parent_note_id UNIQUE(id, title, parent_note_id); diff --git a/db/migrations/2019-04-26-020705_fix_note_constraint/up.sql b/db/migrations/2019-04-26-020705_fix_note_constraint/up.sql new file mode 100644 index 00000000..323f729a --- /dev/null +++ b/db/migrations/2019-04-26-020705_fix_note_constraint/up.sql @@ -0,0 +1,3 @@ +ALTER TABLE notes + DROP CONSTRAINT notes_title_id_parent_note_id, + ADD CONSTRAINT notes_title_user_id_parent_note_id UNIQUE(title, user_id, parent_note_id); diff --git a/db/src/models.rs b/db/src/models.rs index 9347a6eb..f47c098e 100644 --- a/db/src/models.rs +++ b/db/src/models.rs @@ -251,10 +251,12 @@ impl User { db.transaction::<(), diesel::result::Error, _>(|| { use crate::schema::{note_tags_id::dsl::*, tags::dsl::*}; - diesel::insert_into(tags) + // TODO: Server needs Postgres 9.5 to support ON CONFLICT DO NOTHING + // BODY: In the meantime, we will just ignore the result from the following execute. + let _ = diesel::insert_into(tags) .values(&set_tags.iter().map(|t| tag.eq(t)).collect::>()) - .on_conflict_do_nothing() - .execute(db)?; + // .on_conflict_do_nothing() + .execute(db); let all_tags = tags.filter(tag.eq_any(set_tags)).load::(db)?; @@ -343,6 +345,32 @@ mod test { }); } + #[test] + fn test_modifying_tags() { + let db = db().unwrap(); + db.test_transaction::<_, diesel::result::Error, _>(|| { + let user = test_user(&db); + let note = user + .new_note( + &NewNote { + title: "Title".to_owned(), + body: "Body".to_owned(), + parent_note_id: None, + }, + &db, + ) + .unwrap(); + + let note = user + .set_note_tags(note.id, &["Tag1".to_owned(), "Tag2".to_owned()], &db) + .unwrap(); + + assert_eq!(note.tags, vec!["Tag1".to_owned(), "Tag2".to_owned()]); + + Ok(()) + }); + } + #[test] fn test_creating_user() { let db = db().unwrap(); diff --git a/webpack.common.js b/webpack.common.js index 404db83d..65d10bf9 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -14,7 +14,7 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer') module.exports = { entry: './js/index.tsx', output: { - filename: 'js/[name].bundle.js', + filename: 'js/[name].[chunkhash].js', chunkFilename: 'js/[name].[chunkhash].js', publicPath: '/dist/',