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

Function addGeneratedToColumn

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

Source from the content-addressed store, hash-verified

373 },
374
375 async addGeneratedToColumn() {
376 const client = new PGlite();
377
378 const schema1 = {
379 users: pgTable('users', {
380 id: integer('id'),
381 id2: integer('id2'),
382 name: text('name'),
383 generatedName: text('gen_name'),
384 }),
385 };
386 const schema2 = {
387 users: pgTable('users', {
388 id: integer('id'),
389 id2: integer('id2'),
390 name: text('name'),
391 generatedName: text('gen_name').generatedAlwaysAs((): SQL => sql`${schema2.users.name}`),
392 }),
393 };
394
395 const { statements, sqlStatements } = await diffTestSchemasPush(client, schema1, schema2, [], false, ['public']);
396
397 expect(statements).toStrictEqual([
398 {
399 columnAutoIncrement: undefined,
400 columnDefault: undefined,
401 columnGenerated: {
402 as: '"users"."name"',
403 type: 'stored',
404 },
405 columnName: 'gen_name',
406 columnNotNull: false,
407 columnOnUpdate: undefined,
408 columnPk: false,
409 newDataType: 'text',
410 schema: '',
411 tableName: 'users',
412 type: 'alter_table_alter_column_set_generated',
413 },
414 ]);
415 expect(sqlStatements).toStrictEqual([
416 'ALTER TABLE "users" drop column "gen_name";',
417 'ALTER TABLE "users" ADD COLUMN "gen_name" text GENERATED ALWAYS AS ("users"."name") STORED;',
418 ]);
419
420 // for (const st of sqlStatements) {
421 // await client.query(st);
422 // }
423 },
424
425 async dropGeneratedConstraint() {
426 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