Convert Drizzle Schema from MySQL to PostgreSQL

JavaScript pattern

Migrate the Drizzle DB schema from MySQL to PostgreSQL.

Migrate MySQL schema to PostgreSQL

BEFORE
import {
  bigint,
  boolean,
  double,
  int,
  mediumint,
  mysqlTable,
  serial,
  smallint,
  tinyint,
  varchar,
} from 'drizzle-orm/mysql-core';

export const tableOne = mysqlTable('table', {
  id: serial('id').primaryKey().notNull(),
  userId: int('userId'),
  partner: varchar('partner', { length: 20 }).notNull(),
  age: tinyint('age'),
  balance: mediumint('balance'),
  price: double('price'),
  isEnable: boolean('isEnable').notNull().default(true),
});

export const tableTwo = mysqlTable('table_two', {
  id: serial('id').primaryKey().notNull(),
  userId: int('userId'),
  partner: varchar('partner', { length: 20 }).notNull(),
  age: tinyint('age'),
  small: smallint('small'),
  secret: bigint('secret', { mode: 'number' }),
  balance: mediumint('balance'),
  price: double('price'),
});
AFTER
import {
  bigint,
  boolean,
  doublePrecision,
  integer,
  pgTable,
  serial,
  smallint,
  varchar,
} from 'drizzle-orm/pg-core';

export const tableOne = pgTable('table', {
  id: serial('id').primaryKey().notNull(),
  userId: integer('userId'),
  partner: varchar('partner', { length: 20 }).notNull(),
  age: smallint('age'),
  balance: integer('balance'),
  price: doublePrecision('price'),
  isEnable: boolean('isEnable').notNull().default(true),
});

export const tableTwo = pgTable('table_two', {
  id: serial('id').primaryKey().notNull(),
  userId: integer('userId'),
  partner: varchar('partner', { length: 20 }).notNull(),
  age: smallint('age'),
  small: smallint('small'),
  secret: bigint('secret', { mode: 'number' }),
  balance: integer('balance'),
  price: doublePrecision('price'),
});