SeaQL / sea-schema

šŸŒæ SQL schema definition and discovery
https://docs.rs/sea-schema
Apache License 2.0
186 stars 38 forks source link

postgres timestamp mapping error: SQL type `TIMESTAMPTZ`) is not compatible with SQL type `TIMESTAMP` #50

Closed pymongo closed 2 years ago

pymongo commented 2 years ago

Description

I want use postgres timestamp without time zone type in sea-orm

Steps to Reproduce

  1. (in postgres create statement)created_at timestamp without time zone default current_timestamp not null
  2. sea-orm-cli generate entity -o src/tables_codegen
  3. Orders::find().one(&db).await.unwrap().unwrap();

Expected Behavior

The generate code created_at field is

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "orders")]
pub struct Model {
    pub created_at: DateTime,
    ...
}

Actual Behavior

thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: Query("error occurred while decoding column \"paid_at\": mismatched types; Rust type `core::option::Option<chrono::datetime::DateTime<chrono::offset::utc::Utc>>` (as SQL type `TIMESTAMPTZ`) is not compatible with SQL type `TIMESTAMP`")', src/handler/order.rs:17:56

The generate code created_at field is DateTimeUtc type not DateTime (without time zone)

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "orders")]
pub struct Model {
    pub created_at: DateTimeUtc,
    ...
}

Reproduces How Often

always

Versions

ā”œā”€ā”€ sea-orm v0.6.0
ā”‚   ā”œā”€ā”€ sea-orm-macros v0.6.0 (proc-macro)
ā”‚   ā”œā”€ā”€ sea-query v0.21.0
ā”‚   ā”‚   ā”œā”€ā”€ sea-query-derive v0.2.0 (proc-macro)
ā”‚   ā”œā”€ā”€ sea-strum v0.23.0
ā”‚   ā”‚   ā””ā”€ā”€ sea-strum_macros v0.23.0 (proc-macro)

psql --version
psql (PostgreSQL) 13.6

Linux ww 5.10.102-1-MANJARO #1 SMP PREEMPT Wed Feb 23 14:44:40 UTC 2022 x86_64 GNU/Linux

Additional Information

postgres orders table schema

psql (13.6, server 12.9 (Ubuntu 12.9-0ubuntu0.20.04.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
You are now connected to database "w" as user "postgres".
w=# \d orders
                                Table "public.orders"
   Column   |            Type             | Collation | Nullable |      Default      
------------+-----------------------------+-----------+----------+-------------------
 team_id    | bigint                      |           | not null | 
 product_id | bigint                      |           | not null | 
 user_id    | bigint                      |           | not null | 
 service_id | bigint                      |           | not null | 
 status     | order_status                |           | not null | 
 type_      | order_type                  |           | not null | 
 paid_at    | timestamp without time zone |           | not null | 
 price      | integer                     |           | not null | 
 id         | bigint                      |           | not null | 
 created_at | timestamp without time zone |           | not null | CURRENT_TIMESTAMP
pymongo commented 2 years ago

relative issue:

https://github.com/SeaQL/sea-orm/issues/586

billy1624 commented 2 years ago

Hey @pymongo, thanks for the report! It's more related to SeaORM codegen. Please track this issue on SeaQL/sea-orm#586. I'll close this now