Back to Drizzle Orm

UpdateSchema

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

latest656 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
// table schema generated by introspection
import {
  sqliteTable,
  uniqueIndex,
  integer,
  text,
} from "drizzle-orm/sqlite-core";

export const usersTable = sqliteTable(
  "users_table",
  {
    id: integer().primaryKey({ autoIncrement: true }).notNull(),
    name: text().notNull(),
    age: integer().notNull(),
    email: text().notNull(),
    phone: text(),
  },
  (table) => [
    uniqueIndex("users_table_email_unique").on(table.email)
  ]
);