src/mdx/get-started/singlestore/IntrospectSingleStore.mdx
Drizzle Kit provides a CLI command to introspect your database and generate a schema file with migrations. The schema file contains all the information about your database tables, columns, relations, and indices.
For example, you have such table in your database:
CREATE TABLE `users_table` (
`id` int NOT NULL,
`name` varchar(255) NOT NULL,
`age` int NOT NULL,
`email` varchar(255) NOT NULL,
CONSTRAINT `users_table_id` PRIMARY KEY(`id`),
CONSTRAINT `users_table_email_unique` UNIQUE(`email`)
);
Pull your database schema:
npx drizzle-kit pull --init
The result of introspection will be a schema.ts file and meta folder with snapshots of your database schema
Here is an example of the generated schema.ts file:
// table schema generated by introspection
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(),
},
(table) => [
primaryKey({ columns: [table.id], name: 'users_table_id' }),
unique('id').on(table.id),
unique('users_table_email_unique').on(table.email),
],
);
Learn more about introspection in the documentation.