Skip to content

Commit

Permalink
feat(mysql): add support for vector indices (#139)
Browse files Browse the repository at this point in the history
* feat(mysql): add support for vector indices

PlanetScale recently added vector support to their fork of mysql.
If a vector index is added to it, then sea-orm generate entity command
panics because the index type is not recognized by its parser.

This PR adds support for recognizing vector indices as a valid index
type.

Test Plan: Created a planet scale database with a vector index, and ran
`generate entity` command. Verified that after this change, the command
no longer crashes and creates valid files.

* gate behind planetscale feature flag
  • Loading branch information
ammubhave authored Oct 25, 2024
1 parent 50e3811 commit c789ecc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ discovery = ["futures", "parser"]
parser = ["query"]
query = ["def"]
writer = ["def"]
planetscale = []
probe = ["query"]
sqlx-dep = ["sqlx"]
sqlx-all = ["sqlx-mysql", "sqlx-postgres", "sqlx-sqlite"]
Expand Down
3 changes: 3 additions & 0 deletions src/mysql/def/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ pub enum IndexType {
RTree,
#[iden = "SPATIAL"]
Spatial,
#[cfg(feature = "planetscale")]
#[iden = "VECTOR"]
Vector,
}
6 changes: 6 additions & 0 deletions src/mysql/writer/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ impl IndexInfo {
self.idx_type.to_string(),
))));
}
#[cfg(feature = "planetscale")]
IndexType::Vector => {
index.index_type(sea_query::IndexType::Custom(SeaRc::new(Alias::new(
self.idx_type.to_string(),
))));
}
}
index
}
Expand Down

0 comments on commit c789ecc

Please sign in to comment.