MCPcopy
hub / github.com/drizzle-team/drizzle-orm / addGeneratedColumn

Function addGeneratedColumn

drizzle-kit/tests/push/pg.test.ts:328–373  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

326 },
327
328 async addGeneratedColumn() {
329 const client = new PGlite();
330
331 const schema1 = {
332 users: pgTable('users', {
333 id: integer('id'),
334 id2: integer('id2'),
335 name: text('name'),
336 }),
337 };
338 const schema2 = {
339 users: pgTable('users', {
340 id: integer('id'),
341 id2: integer('id2'),
342 name: text('name'),
343 generatedName: text('gen_name').generatedAlwaysAs((): SQL => sql`${schema2.users.name}`),
344 }),
345 };
346
347 const { statements, sqlStatements } = await diffTestSchemasPush(client, schema1, schema2, [], false, ['public']);
348
349 expect(statements).toStrictEqual([
350 {
351 column: {
352 generated: {
353 as: '"users"."name"',
354 type: 'stored',
355 },
356 name: 'gen_name',
357 notNull: false,
358 primaryKey: false,
359 type: 'text',
360 },
361 schema: '',
362 tableName: 'users',
363 type: 'alter_table_add_column',
364 },
365 ]);
366 expect(sqlStatements).toStrictEqual([
367 'ALTER TABLE "users" ADD COLUMN "gen_name" text GENERATED ALWAYS AS ("users"."name") STORED;',
368 ]);
369
370 // for (const st of sqlStatements) {
371 // await client.query(st);
372 // }
373 },
374
375 async addGeneratedToColumn() {
376 const client = new PGlite();

Callers

nothing calls this directly

Calls 6

pgTableFunction · 0.90
integerFunction · 0.90
textFunction · 0.90
sqlFunction · 0.90
diffTestSchemasPushFunction · 0.90
generatedAlwaysAsMethod · 0.45

Tested by

no test coverage detected