-
Hi, I am playing with diesel on PG and it appears I don't get the desired table when I generate the migration from This is what I want: -- Your SQL goes here
CREATE TABLE "user" (
id SERIAL PRIMARY KEY,
username VARCHAR NOT NULL
);
CREATE TABLE resource_server (
id SERIAL PRIMARY KEY,
uri VARCHAR NOT NULL
); This migration generate this schema.rs: diesel::table! {
resource_server (id) {
id -> Int4,
uri -> Varchar,
}
}
diesel::table! {
user (id) {
id -> Int4,
username -> Varchar,
}
}
diesel::allow_tables_to_appear_in_same_query!(
resource_server,
user,
); But if I try to generate the SQL migration from this -- Your SQL goes here
CREATE TABLE "resource_server"(
"id" INT4 NOT NULL PRIMARY KEY,
"uri" VARCHAR NOT NULL
);
CREATE TABLE "user"(
"id" INT4 NOT NULL PRIMARY KEY,
"username" VARCHAR NOT NULL
); The ids should be 'SERIAL' and not 'INT4'. I tried to generate migrations from this modified diesel::table! {
resource_server (id) {
id -> Serial,
uri -> Varchar,
}
}
diesel::table! {
user (id) {
id -> Serial,
username -> Varchar,
}
}
diesel::allow_tables_to_appear_in_same_query!(
resource_server,
user,
); But then I lose the primary key constraint on ids. Did I miss something ? I suspect it's a bug, but maybe I am wrong. Let me know. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
There is no way for the CLI tool to know if a user really wants to use a auto incrementing ID there or not as there are also cases where this is not desired. In fact the CLI tool will more or less literally use the types as provided by the user. In that case this means if you write |
Beta Was this translation helpful? Give feedback.
There is no way for the CLI tool to know if a user really wants to use a auto incrementing ID there or not as there are also cases where this is not desired. In fact the CLI tool will more or less literally use the types as provided by the user. In that case this means if you write
Int4
you get anInt4
, if you writeSerial
you getSerial
and so on. This is expected behaviour as we don't want to do any heavy processing at that point. After all we generate the SQL for you, but don't automatically apply the migration. The main reason for that is to give you as a user the possibility to modify the generated migration afterwards, for example by tweaking types or adding constraints.