Specifying array types when generating migrations #301
-
So, according to SeaORM's docs, in order to specify a column is an array (assuming you're using Postgres), you just declare the struct field as being a #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "collection")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub integers: Vec<i32>,
pub integers_opt: Option<Vec<i32>>,
pub floats: Vec<f32>,
pub doubles: Vec<f64>,
pub strings: Vec<String>,
} I tried searching the docs and couldn't find the list of types we can specify when generating a migration. Am I correct in assuming that specifying columns as arrays of ints, etc. still hasn't been implemented in the CLI? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
It sounds like you are having a similar issue I was having with floats. I couldn't find documentation on how to use them as the CLI registry/schema does not appear to offer that mapping when generating. The same appears to be the case for Vec. However, if you just use underlying SeaORM logic you'll have no problem. So once you have a migration ready you can modify it. Let's say in the migration you generated you have a single integer value like so:
You can change that like so:
Now you need to run |
Beta Was this translation helpful? Give feedback.
-
Yes. Something did not work correctly if that was the outcome. Presumably you got your database in a state to where the migration ran again after the modification, right? I believe the difference is that when you apply the modifiers with SeaORM you get back a mutable reference. I think loco's schema modifiers could return mutable references and it would be equivalent, they just don't. |
Beta Was this translation helpful? Give feedback.
-
Just to update: I just dropped my database and recreated it. It all worked. |
Beta Was this translation helpful? Give feedback.
It sounds like you are having a similar issue I was having with floats. I couldn't find documentation on how to use them as the CLI registry/schema does not appear to offer that mapping when generating.
The same appears to be the case for Vec. However, if you just use underlying SeaORM logic you'll have no problem. So once you have a migration ready you can modify it. Let's say in the migration you generated you have a single integer value like so: