Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

me: fix regression in enum column type diffing #3374

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ impl SqlSchemaDifferFlavour for PostgresFlavour {

fn column_type_change(&self, columns: Pair<ColumnWalker<'_>>) -> Option<ColumnTypeChange> {
// Handle the enum cases first.
match columns.map(|col| col.column_type_family().as_enum()).into_tuple() {
match columns
.map(|col| col.column_type_family_as_enum().map(|e| e.name()))
.into_tuple()
{
(Some(previous_enum), Some(next_enum)) if previous_enum == next_enum => return None,
(Some(_), Some(_)) => return Some(ColumnTypeChange::NotCastable),
(None, Some(_)) | (Some(_), None) => return Some(ColumnTypeChange::NotCastable),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// tags=mysql

datasource mydb {
provider = "mysql"
url = env("TEST_DATABASE_URL")
}

model MyTable {
id Int @id
k Kind? @default(error)
r Result @default(succeeded)
}

enum Result {
succeeded
failed
}

enum Kind {
info
warning
error
}
// Expected Migration:
// -- CreateTable
// CREATE TABLE `MyTable` (
// `id` INTEGER NOT NULL,
// `k` ENUM('info', 'warning', 'error') NULL DEFAULT 'error',
// `r` ENUM('succeeded', 'failed') NOT NULL DEFAULT 'succeeded',
//
// PRIMARY KEY (`id`)
// ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// tags=postgres
// exclude=cockroachdb

datasource mydb {
provider = "postgresql"
url = env("TEST_DATABASE_URL")
}

model MyTable {
id Int @id
a Activity @default(SLEEPING)
k Kind? @default(error)
r Result @default(succeeded)
}

enum Result {
succeeded
failed
}

enum Activity {
DANCING
SLEEPING
READING
}

enum Kind {
info
warning
error
}

// Expected Migration:
// -- CreateEnum
// CREATE TYPE "Result" AS ENUM ('succeeded', 'failed');
//
// -- CreateEnum
// CREATE TYPE "Activity" AS ENUM ('DANCING', 'SLEEPING', 'READING');
//
// -- CreateEnum
// CREATE TYPE "Kind" AS ENUM ('info', 'warning', 'error');
//
// -- CreateTable
// CREATE TABLE "MyTable" (
// "id" INTEGER NOT NULL,
// "a" "Activity" NOT NULL DEFAULT 'SLEEPING',
// "k" "Kind" DEFAULT 'error',
// "r" "Result" NOT NULL DEFAULT 'succeeded',
//
// CONSTRAINT "MyTable_pkey" PRIMARY KEY ("id")
// );