Back to Drizzle Orm

UpdateSchema

src/mdx/get-started/singlestore/UpdateSchema.mdx

latest819 B
Original Source

If you want to update your table schema, you can do it in the schema.ts file. For example, let's add a new column phone to the users_table:

typescript
import {
  singlestoreTable,
  singlestoreSchema,
  AnySingleStoreColumn,
  primaryKey,
  unique,
  varchar,
  int,
} from 'drizzle-orm/singlestore-core';
import { sql } from 'drizzle-orm';

export const usersTable = singlestoreTable(
  'users_table',
  {
    id: int().notNull(),
    name: varchar({ length: 255 }).notNull(),
    age: int().notNull(),
    email: varchar({ length: 255 }).notNull(),
    phone: varchar({ length: 255 }),
  },
  (table) => [
    primaryKey({ columns: [table.id], name: 'users_table_id' }),
    unique('id').on(table.id),
    unique('users_table_email_unique').on(table.email),
  ],
);