Missing primary_key attributes when generating from a DB with partitions
omjadas opened this issue · 2 comments
Description
When a postgres DB contains partitions of a partitioned table (if a partitioned table is present but doesn't have any partitions then this issue does not happen). If sea-orm-cli is used to generate entities none of the entities have the primary_key
attribute (even non partitioned tables). This seems to have worked prior to 0.12.0
.
Steps to Reproduce
- Create a table
- Create a partitioned table
- Create a partition of the partitioned table
- Generate entities using
sea-orm-cli generate entity
Expected Behavior
Generated entities have primary_key
attributes
Actual Behavior
Generated entities do not primary_key
attributes
Reproduces How Often
Always
Workarounds
Manually add primary_key
attributes after generating entities.
Reproducible Example
CREATE TABLE test_table (
id serial,
name text,
PRIMARY KEY (id)
);
CREATE TABLE partitioned_table (
partition_key int,
id serial,
name text,
PRIMARY KEY (partition_key, id)
) PARTITION BY HASH (partition_key);
CREATE TABLE partitioned_table_0
PARTITION OF partitioned_table
FOR VALUES WITH (MODULUS 1, REMAINDER 0);
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "partitioned_table")]
pub struct Model {
pub partition_key: i32,
pub id: i64,
#[sea_orm(column_type = "Text", nullable)]
pub name: Option<String>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "test_table")]
pub struct Model {
pub id: i32,
#[sea_orm(column_type = "Text", nullable)]
pub name: Option<String>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
Versions
Broken in 0.12.14
. I have also tested 0.11.3
and when using it the primary_key
attributes are correctly set.
I just compiled the latest main
branch version of sea-orm-cli
and in my case it still failed to add that primary key attribute.
I just compiled the latest
main
branch version ofsea-orm-cli
and in my case it still failed to add that primary key attribute.
Looks like we are waiting on a new release of https://github.com/SeaQL/sea-schema