Should drizzle-kit introspect produce the same content as my existing schema?

In my sveltekit app /lib/server/schema.ts is my schema, changes are made and then drizzle-kit push pushed to my prod server. If I run a drizzle-kit introspect should this pulled schema == my /lib/server/schema.ts? I was under the impression it would be, and that it was prior to 0.21.0 upgrade but I could 100% be mistaken.
6 Replies
Andrii Sherman
Andrii Sherman7mo ago
it should could you please share the way to reproduce it, so we can fix it?
jaslr
jaslrOP7mo ago
I'm trying to find a way to reproduce this, in the meantime, is this the correct workflow for updating my schema: 1. Update schema within server\schema.ts where this is opening lines prior to table definitions:
import {
pgTable,
foreignKey,
pgEnum,
serial,
integer,
uuid,
index,
text,
bigint,
timestamp,
unique,
varchar,
json,
boolean
} from 'drizzle-orm/pg-core';
import { sql } from 'drizzle-orm';

export const appPermission = pgEnum('app_permission', [
...permissions...
]);
export const appRole = pgEnum('app_role', [...roles...]);
import {
pgTable,
foreignKey,
pgEnum,
serial,
integer,
uuid,
index,
text,
bigint,
timestamp,
unique,
varchar,
json,
boolean
} from 'drizzle-orm/pg-core';
import { sql } from 'drizzle-orm';

export const appPermission = pgEnum('app_permission', [
...permissions...
]);
export const appRole = pgEnum('app_role', [...roles...]);
and because I am developing straight into supabase, I run drizzle-kit push , where this is drizzle.config.ts:
import dotenv from 'dotenv';
dotenv.config();

import type { Config } from "drizzle-kit";

export default {
schema: "./src/lib/server/schema.ts",
out: "./drizzle",
dialect: 'postgresql',
dbCredentials: {
// supabase env credentials
},
} as Config;
import dotenv from 'dotenv';
dotenv.config();

import type { Config } from "drizzle-kit";

export default {
schema: "./src/lib/server/schema.ts",
out: "./drizzle",
dialect: 'postgresql',
dbCredentials: {
// supabase env credentials
},
} as Config;
2. I then run drizzle-kit introspect and my file in drizzle\schema.ts has a whole bunch of things NOT in my server\schema.ts such as:
import { pgTable, index, foreignKey, pgEnum, serial, uuid, integer, text, unique, bigint, timestamp, varchar, json, boolean } from "drizzle-orm/pg-core"
import { sql } from "drizzle-orm"
export const aal_level = pgEnum("aal_level", ['aal1', 'aal2', 'aal3'])
export const code_challenge_method = pgEnum("code_challenge_method", ['s256', 'plain'])
export const factor_status = pgEnum("factor_status", ['unverified', 'verified'])
export const appPermission = pgEnum('app_permission', [
...permissions...
]);
export const appRole = pgEnum('app_role', [...roles...]);
import { pgTable, index, foreignKey, pgEnum, serial, uuid, integer, text, unique, bigint, timestamp, varchar, json, boolean } from "drizzle-orm/pg-core"
import { sql } from "drizzle-orm"
export const aal_level = pgEnum("aal_level", ['aal1', 'aal2', 'aal3'])
export const code_challenge_method = pgEnum("code_challenge_method", ['s256', 'plain'])
export const factor_status = pgEnum("factor_status", ['unverified', 'verified'])
export const appPermission = pgEnum('app_permission', [
...permissions...
]);
export const appRole = pgEnum('app_role', [...roles...]);
note the exports aal_level, code_challenge_method, factor_status also the table names in my original schema.ts are camelCase but when i introspect they're snake_case 🤷‍♂️ This is definitely user error, but I'm not sure how to get around it.
Andrii Sherman
Andrii Sherman7mo ago
you can change casing for introspect
Andrii Sherman
Andrii Sherman7mo ago
Drizzle ORM - Config Reference
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Andrii Sherman
Andrii Sherman7mo ago
please check this part of docs
jaslr
jaslrOP7mo ago
Thanks for the reply @Andrew Sherman I have fixed the casing now. However my pulled schema has a lot of exports such as:
export const aalLevel = pgEnum("aal_level", ['aal1', 'aal2', 'aal3'])
export const codeChallengeMethod = pgEnum("code_challenge_method", ['s256', 'plain'])
export const factorStatus = pgEnum("factor_status", ['unverified', 'verified'])
export const factorType = pgEnum("factor_type", ['totp', 'webauthn'])
export const oneTimeTokenType = pgEnum("one_time_token_type", ['confirmation_token', 'reauthentication_token', 'recovery_token', 'email_change_token_new', 'email_change_token_current', 'phone_change_token'])
export const keyStatus = pgEnum("key_status", ['default', 'valid', 'invalid', 'expired'])
export const keyType = pgEnum("key_type", ['aead-ietf', 'aead-det', 'hmacsha512', 'hmacsha256', 'auth', 'shorthash', 'generichash', 'kdf', 'secretbox', 'secretstream', 'stream_xchacha20'])
export const aalLevel = pgEnum("aal_level", ['aal1', 'aal2', 'aal3'])
export const action = pgEnum("action", ['INSERT', 'UPDATE', 'DELETE', 'TRUNCATE', 'ERROR'])
export const codeChallengeMethod = pgEnum("code_challenge_method", ['s256', 'plain'])
export const equalityOp = pgEnum("equality_op", ['eq', 'neq', 'lt', 'lte', 'gt', 'gte', 'in'])
export const factorStatus = pgEnum("factor_status", ['unverified', 'verified'])
export const factorType = pgEnum("factor_type", ['totp', 'webauthn'])

export const action = pgEnum("action", ['INSERT', 'UPDATE', 'DELETE', 'TRUNCATE', 'ERROR'])
export const equalityOp = pgEnum("equality_op", ['eq', 'neq', 'lt', 'lte', 'gt', 'gte', 'in'])
export const aalLevel = pgEnum("aal_level", ['aal1', 'aal2', 'aal3'])
export const codeChallengeMethod = pgEnum("code_challenge_method", ['s256', 'plain'])
export const factorStatus = pgEnum("factor_status", ['unverified', 'verified'])
export const factorType = pgEnum("factor_type", ['totp', 'webauthn'])
export const oneTimeTokenType = pgEnum("one_time_token_type", ['confirmation_token', 'reauthentication_token', 'recovery_token', 'email_change_token_new', 'email_change_token_current', 'phone_change_token'])
export const keyStatus = pgEnum("key_status", ['default', 'valid', 'invalid', 'expired'])
export const keyType = pgEnum("key_type", ['aead-ietf', 'aead-det', 'hmacsha512', 'hmacsha256', 'auth', 'shorthash', 'generichash', 'kdf', 'secretbox', 'secretstream', 'stream_xchacha20'])
export const aalLevel = pgEnum("aal_level", ['aal1', 'aal2', 'aal3'])
export const action = pgEnum("action", ['INSERT', 'UPDATE', 'DELETE', 'TRUNCATE', 'ERROR'])
export const codeChallengeMethod = pgEnum("code_challenge_method", ['s256', 'plain'])
export const equalityOp = pgEnum("equality_op", ['eq', 'neq', 'lt', 'lte', 'gt', 'gte', 'in'])
export const factorStatus = pgEnum("factor_status", ['unverified', 'verified'])
export const factorType = pgEnum("factor_type", ['totp', 'webauthn'])

export const action = pgEnum("action", ['INSERT', 'UPDATE', 'DELETE', 'TRUNCATE', 'ERROR'])
export const equalityOp = pgEnum("equality_op", ['eq', 'neq', 'lt', 'lte', 'gt', 'gte', 'in'])
which just aren't in my original schema. Could this be the product of a migration that I could've erroneously started and if so, can I roll back or quash that migration?
Want results from more Discord servers?
Add your server