Skip to content

Commit

Permalink
Add equality of KnownId(t) and Known(t) (#234)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: James Oakley <james@electronstudio.org>
  • Loading branch information
jayvdb and Electron100 authored Apr 5, 2024
1 parent 372a4ec commit c00f027
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 444 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ install :
cd butane_cli && $(CARGO) install --path .

regenerate-example-migrations :
for dir in examples/*; do (cd $$dir; cargo +stable run -p butane_cli --all-features -- regenerate); done
for dir in examples/*; do \
(cd $$dir; cargo +stable run -p butane_cli --all-features -- regenerate; \
cargo +stable run -p butane_cli --all-features -- embed); \
done
19 changes: 18 additions & 1 deletion butane_core/src/migrations/adb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl ATable {
}

/// SqlType which may not yet be known.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Deserialize, Eq, Serialize)]
pub enum DeferredSqlType {
Known(SqlType), // Kept for backwards deserialization compat, supplanted by KnownId
KnownId(TypeIdentifier),
Expand All @@ -351,6 +351,23 @@ impl DeferredSqlType {
}
}
}
/// Compare, with Known and KnownId being identical if they contain the same type.
impl PartialEq<DeferredSqlType> for DeferredSqlType {
fn eq(&self, other: &DeferredSqlType) -> bool {
match (self, other) {
(Self::Known(sqltype), Self::Known(other_sqltype)) => *sqltype == *other_sqltype,
(Self::KnownId(ty_id), Self::KnownId(other_ty_id)) => *ty_id == *other_ty_id,
(Self::Known(sqltype), Self::KnownId(other_ty_id)) => {
TypeIdentifier::Ty(sqltype.clone()) == *other_ty_id
}
(Self::KnownId(ty_id), Self::Known(other_sqltype)) => {
*ty_id == TypeIdentifier::Ty(other_sqltype.clone())
}
(Self::Deferred(key), Self::Deferred(other_key)) => *key == *other_key,
_ => false,
}
}
}
impl From<TypeIdentifier> for DeferredSqlType {
fn from(id: TypeIdentifier) -> Self {
DeferredSqlType::KnownId(id)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"from_name": "20201229_171630604_likes",
"table_bases": {
"Blog": "20201229_144636751_init",
"Tag": "20201229_144636751_init"
},
"backends": [
"sqlite",
"pg"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,89 +1,3 @@
CREATE TABLE Blog__butane_tmp (
id BIGSERIAL NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL
);
INSERT INTO Blog__butane_tmp SELECT id, "name" FROM Blog;
DROP TABLE Blog;
ALTER TABLE Blog__butane_tmp RENAME TO Blog;
CREATE TABLE Blog__butane_tmp (
id BIGSERIAL NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL
);
INSERT INTO Blog__butane_tmp SELECT id, "name" FROM Blog;
DROP TABLE Blog;
ALTER TABLE Blog__butane_tmp RENAME TO Blog;
CREATE TABLE Post__butane_tmp (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL,
blog BIGINT NOT NULL,
byline TEXT ,
likes INTEGER NOT NULL
);
INSERT INTO Post__butane_tmp SELECT id, title, body, published, blog, byline, likes FROM Post;
DROP TABLE Post;
ALTER TABLE Post__butane_tmp RENAME TO Post;
CREATE TABLE Post__butane_tmp (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL,
blog BIGINT NOT NULL,
byline TEXT ,
likes INTEGER NOT NULL
);
INSERT INTO Post__butane_tmp SELECT id, title, body, published, blog, byline, likes FROM Post;
DROP TABLE Post;
ALTER TABLE Post__butane_tmp RENAME TO Post;
CREATE TABLE Post__butane_tmp (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL,
blog BIGINT NOT NULL,
byline TEXT ,
likes INTEGER NOT NULL
);
INSERT INTO Post__butane_tmp SELECT id, title, body, published, blog, byline, likes FROM Post;
DROP TABLE Post;
ALTER TABLE Post__butane_tmp RENAME TO Post;
CREATE TABLE Post__butane_tmp (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL,
blog BIGINT NOT NULL,
byline TEXT ,
likes INTEGER NOT NULL
);
INSERT INTO Post__butane_tmp SELECT id, title, body, published, blog, byline, likes FROM Post;
DROP TABLE Post;
ALTER TABLE Post__butane_tmp RENAME TO Post;
CREATE TABLE Post__butane_tmp (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL,
blog BIGINT NOT NULL,
byline TEXT ,
likes INTEGER NOT NULL
);
INSERT INTO Post__butane_tmp SELECT id, title, body, published, blog, byline, likes FROM Post;
DROP TABLE Post;
ALTER TABLE Post__butane_tmp RENAME TO Post;
CREATE TABLE Post__butane_tmp (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL,
blog BIGINT NOT NULL,
byline TEXT ,
likes INTEGER NOT NULL
);
INSERT INTO Post__butane_tmp SELECT id, title, body, published, blog, byline, likes FROM Post;
DROP TABLE Post;
ALTER TABLE Post__butane_tmp RENAME TO Post;
CREATE TABLE Post__butane_tmp (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
Expand Down Expand Up @@ -111,9 +25,3 @@ has TEXT NOT NULL
INSERT INTO Post_tags_Many__butane_tmp SELECT owner, has FROM Post_tags_Many;
DROP TABLE Post_tags_Many;
ALTER TABLE Post_tags_Many__butane_tmp RENAME TO Post_tags_Many;
CREATE TABLE Tag__butane_tmp (
tag TEXT NOT NULL PRIMARY KEY
);
INSERT INTO Tag__butane_tmp SELECT tag FROM Tag;
DROP TABLE Tag;
ALTER TABLE Tag__butane_tmp RENAME TO Tag;
Original file line number Diff line number Diff line change
@@ -1,95 +1,3 @@
CREATE TABLE Blog__butane_tmp (
id BIGSERIAL NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL
);
INSERT INTO Blog__butane_tmp SELECT id, "name" FROM Blog;
DROP TABLE Blog;
ALTER TABLE Blog__butane_tmp RENAME TO Blog;
CREATE TABLE Blog__butane_tmp (
id BIGSERIAL NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL
);
INSERT INTO Blog__butane_tmp SELECT id, "name" FROM Blog;
DROP TABLE Blog;
ALTER TABLE Blog__butane_tmp RENAME TO Blog;
CREATE TABLE Post__butane_tmp (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL,
blog BIGINT NOT NULL,
byline TEXT ,
likes INTEGER NOT NULL
);
ALTER TABLE Post__butane_tmp ADD FOREIGN KEY (blog) REFERENCES Blog(id);
INSERT INTO Post__butane_tmp SELECT id, title, body, published, blog, byline, likes FROM Post;
DROP TABLE Post;
ALTER TABLE Post__butane_tmp RENAME TO Post;
CREATE TABLE Post__butane_tmp (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL,
blog BIGINT NOT NULL,
byline TEXT ,
likes INTEGER NOT NULL
);
ALTER TABLE Post__butane_tmp ADD FOREIGN KEY (blog) REFERENCES Blog(id);
INSERT INTO Post__butane_tmp SELECT id, title, body, published, blog, byline, likes FROM Post;
DROP TABLE Post;
ALTER TABLE Post__butane_tmp RENAME TO Post;
CREATE TABLE Post__butane_tmp (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL,
blog BIGINT NOT NULL,
byline TEXT ,
likes INTEGER NOT NULL
);
ALTER TABLE Post__butane_tmp ADD FOREIGN KEY (blog) REFERENCES Blog(id);
INSERT INTO Post__butane_tmp SELECT id, title, body, published, blog, byline, likes FROM Post;
DROP TABLE Post;
ALTER TABLE Post__butane_tmp RENAME TO Post;
CREATE TABLE Post__butane_tmp (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL,
blog BIGINT NOT NULL,
byline TEXT ,
likes INTEGER NOT NULL
);
ALTER TABLE Post__butane_tmp ADD FOREIGN KEY (blog) REFERENCES Blog(id);
INSERT INTO Post__butane_tmp SELECT id, title, body, published, blog, byline, likes FROM Post;
DROP TABLE Post;
ALTER TABLE Post__butane_tmp RENAME TO Post;
CREATE TABLE Post__butane_tmp (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL,
blog BIGINT NOT NULL,
byline TEXT ,
likes INTEGER NOT NULL
);
ALTER TABLE Post__butane_tmp ADD FOREIGN KEY (blog) REFERENCES Blog(id);
INSERT INTO Post__butane_tmp SELECT id, title, body, published, blog, byline, likes FROM Post;
DROP TABLE Post;
ALTER TABLE Post__butane_tmp RENAME TO Post;
CREATE TABLE Post__butane_tmp (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL,
blog BIGINT NOT NULL,
byline TEXT ,
likes INTEGER NOT NULL
);
ALTER TABLE Post__butane_tmp ADD FOREIGN KEY (blog) REFERENCES Blog(id);
INSERT INTO Post__butane_tmp SELECT id, title, body, published, blog, byline, likes FROM Post;
DROP TABLE Post;
ALTER TABLE Post__butane_tmp RENAME TO Post;
CREATE TABLE Post__butane_tmp (
id SERIAL NOT NULL PRIMARY KEY,
title TEXT NOT NULL,
Expand Down Expand Up @@ -120,9 +28,3 @@ ALTER TABLE Post_tags_Many__butane_tmp ADD FOREIGN KEY (has) REFERENCES Tag(tag)
INSERT INTO Post_tags_Many__butane_tmp SELECT owner, has FROM Post_tags_Many;
DROP TABLE Post_tags_Many;
ALTER TABLE Post_tags_Many__butane_tmp RENAME TO Post_tags_Many;
CREATE TABLE Tag__butane_tmp (
tag TEXT NOT NULL PRIMARY KEY
);
INSERT INTO Tag__butane_tmp SELECT tag FROM Tag;
DROP TABLE Tag;
ALTER TABLE Tag__butane_tmp RENAME TO Tag;
Loading

0 comments on commit c00f027

Please sign in to comment.