Skip to content

Commit 5c174f2

Browse files
committed
+
1 parent 7f424fe commit 5c174f2

File tree

8 files changed

+43
-73
lines changed

8 files changed

+43
-73
lines changed

drizzle-kit/src/cli/commands/up-postgres.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ export const upToV8 = (it: Record<string, any>): { snapshot: PostgresSnapshot; h
120120
cycle: column.identity.cycle ?? null,
121121
}
122122
: null,
123-
default: typeof column.default === 'undefined'
124-
? null
125-
: { type: 'unknown', value: trimDefaultValueSuffix(String(column.default)) },
123+
default: typeof column.default === 'undefined' ? null : trimDefaultValueSuffix(String(column.default)),
126124
});
127125
}
128126

drizzle-kit/src/dialects/postgres/ddl.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ export const createDDL = () => {
1616
typeSchema: 'string?',
1717
notNull: 'boolean',
1818
dimensions: 'number',
19-
default: {
20-
value: 'string',
21-
type: ['null', 'boolean', 'number', 'string', 'bigint', 'json', 'func', 'unknown'],
22-
},
19+
default: 'string?',
2320
generated: {
2421
type: ['stored'],
2522
as: 'string',

drizzle-kit/src/dialects/postgres/diff.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,8 @@ export const ddlDiff = async (
740740
|| (it.$left.type === 'jsonb' && it.$right.type === 'jsonb'))
741741
) {
742742
if (it.default.from !== null && it.default.to !== null) {
743-
const left = stringify(parse(trimChar(it.default.from.value, "'")));
744-
const right = stringify(parse(trimChar(it.default.to.value, "'")));
743+
const left = stringify(parse(trimChar(it.default.from, "'")));
744+
const right = stringify(parse(trimChar(it.default.to, "'")));
745745
if (left === right) {
746746
delete it.default;
747747
}

drizzle-kit/src/dialects/postgres/drizzle.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,41 +178,37 @@ export const defaultFromColumn = (
178178
sql = trimDefaultValueSuffix(sql);
179179

180180
// TODO: check if needed
181-
182181
// const isText = /^'(?:[^']|'')*'$/.test(sql);
183182
// sql = isText ? trimChar(sql, "'") : sql;
184183

185-
return {
186-
value: sql,
187-
type: 'unknown',
188-
};
184+
return sql;
189185
}
190186

191187
const { baseColumn, isEnum } = unwrapColumn(base);
192188
const grammarType = typeFor(base.getSQLType(), isEnum);
193189
if (is(baseColumn, PgPointTuple) || is(baseColumn, PgPointObject)) {
194190
return dimensions > 0 && Array.isArray(def)
195191
? def.flat(5).length === 0
196-
? { value: "'{}'", type: 'unknown' }
192+
? "'{}'"
197193
: Point.defaultArrayFromDrizzle(def, dimensions, baseColumn.mode)
198194
: Point.defaultFromDrizzle(def, baseColumn.mode);
199195
}
200196
if (is(baseColumn, PgLineABC) || is(baseColumn, PgLineTuple)) {
201197
return dimensions > 0 && Array.isArray(def)
202198
? def.flat(5).length === 0
203-
? { value: "'{}'", type: 'unknown' }
199+
? "'{}'"
204200
: Line.defaultArrayFromDrizzle(def, dimensions, baseColumn.mode)
205201
: Line.defaultFromDrizzle(def, baseColumn.mode);
206202
}
207203
if (is(baseColumn, PgGeometry) || is(baseColumn, PgGeometryObject)) {
208204
return dimensions > 0 && Array.isArray(def)
209205
? def.flat(5).length === 0
210-
? { value: "'{}'", type: 'unknown' }
206+
? "'{}'"
211207
: GeometryPoint.defaultArrayFromDrizzle(def, dimensions, baseColumn.mode, baseColumn.srid)
212208
: GeometryPoint.defaultFromDrizzle(def, baseColumn.mode, baseColumn.srid);
213209
}
214210
if (dimensions > 0 && Array.isArray(def)) {
215-
if (def.flat(5).length === 0) return { value: "'{}'", type: 'unknown' };
211+
if (def.flat(5).length === 0) return "'{}'";
216212

217213
return grammarType.defaultArrayFromDrizzle(def, dimensions);
218214
}

drizzle-kit/tests/cockroach/policy.test.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,9 @@ test('create table with rls enabled', async ({ db }) => {
609609
const schema1 = {};
610610

611611
const schema2 = {
612-
users: cockroachTable('users', {
612+
users: cockroachTable.withRLS('users', {
613613
id: int4('id').primaryKey(),
614-
}).enableRLS(),
614+
}),
615615
};
616616

617617
const { sqlStatements: st } = await diff(schema1, schema2, []);
@@ -638,9 +638,9 @@ test('enable rls force', async ({ db }) => {
638638
};
639639

640640
const schema2 = {
641-
users: cockroachTable('users', {
641+
users: cockroachTable.withRLS('users', {
642642
id: int4('id').primaryKey(),
643-
}).enableRLS(),
643+
}),
644644
};
645645

646646
const { sqlStatements: st } = await diff(schema1, schema2, []);
@@ -660,9 +660,9 @@ test('enable rls force', async ({ db }) => {
660660

661661
test('disable rls force', async ({ db }) => {
662662
const schema1 = {
663-
users: cockroachTable('users', {
663+
users: cockroachTable.withRLS('users', {
664664
id: int4('id').primaryKey(),
665-
}).enableRLS(),
665+
}),
666666
};
667667

668668
const schema2 = {
@@ -698,9 +698,9 @@ test('drop policy with enabled rls', async ({ db }) => {
698698

699699
const schema2 = {
700700
role,
701-
users: cockroachTable('users', {
701+
users: cockroachTable.withRLS('users', {
702702
id: int4('id').primaryKey(),
703-
}).enableRLS(),
703+
}),
704704
};
705705

706706
const { sqlStatements: st } = await diff(schema1, schema2, []);
@@ -723,16 +723,16 @@ test('drop policy with enabled rls #2', async ({ db }) => {
723723

724724
const schema1 = {
725725
role,
726-
users: cockroachTable('users', {
726+
users: cockroachTable.withRLS('users', {
727727
id: int4('id').primaryKey(),
728-
}, () => [cockroachPolicy('test', { to: [role] })]).enableRLS(),
728+
}, () => [cockroachPolicy('test', { to: [role] })]),
729729
};
730730

731731
const schema2 = {
732732
role,
733-
users: cockroachTable('users', {
733+
users: cockroachTable.withRLS('users', {
734734
id: int4('id').primaryKey(),
735-
}).enableRLS(),
735+
}),
736736
};
737737

738738
const { sqlStatements: st } = await diff(schema1, schema2, []);
@@ -753,18 +753,18 @@ test('drop policy with enabled rls #2', async ({ db }) => {
753753

754754
test('add policy with enabled rls', async ({ db }) => {
755755
const schema1 = {
756-
users: cockroachTable('users', {
756+
users: cockroachTable.withRLS('users', {
757757
id: int4('id').primaryKey(),
758-
}).enableRLS(),
758+
}),
759759
};
760760

761761
const role = cockroachRole('manager');
762762

763763
const schema2 = {
764764
role,
765-
users: cockroachTable('users', {
765+
users: cockroachTable.withRLS('users', {
766766
id: int4('id').primaryKey(),
767-
}, () => [cockroachPolicy('test', { to: ['current_user', role] })]).enableRLS(),
767+
}, () => [cockroachPolicy('test', { to: ['current_user', role] })]),
768768
};
769769

770770
const { sqlStatements: st } = await diff(schema1, schema2, []);
@@ -789,19 +789,19 @@ test('add policy with enabled rls #2', async ({ db }) => {
789789
const role2 = cockroachRole('owner');
790790
const schema1 = {
791791
role2,
792-
users: cockroachTable('users', {
792+
users: cockroachTable.withRLS('users', {
793793
id: int4('id').primaryKey(),
794-
}).enableRLS(),
794+
}),
795795
};
796796

797797
const role = cockroachRole('manager');
798798

799799
const schema2 = {
800800
role2,
801801
role,
802-
users: cockroachTable('users', {
802+
users: cockroachTable.withRLS('users', {
803803
id: int4('id').primaryKey(),
804-
}, () => [cockroachPolicy('test', { to: [role2, role] })]).enableRLS(),
804+
}, () => [cockroachPolicy('test', { to: [role2, role] })]),
805805
};
806806

807807
const { sqlStatements: st } = await diff(schema1, schema2, []);
@@ -1079,9 +1079,9 @@ test('unlink non-schema table', async ({ db }) => {
10791079
});
10801080

10811081
test('add policy + link non-schema table', async ({ db }) => {
1082-
const cities = cockroachTable('cities', {
1082+
const cities = cockroachTable.withRLS('cities', {
10831083
id: int4('id').primaryKey(),
1084-
}).enableRLS();
1084+
});
10851085

10861086
const schema1 = {
10871087
cities,

drizzle-kit/tests/postgres/big.test.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

drizzle-kit/tests/postgres/entity-filter.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,15 @@ test('push schema #10', async () => {
332332
const { sqlStatements: pst } = await push({ db, to });
333333
expect(pst).toStrictEqual([]);
334334
});
335+
336+
test('huge schema #1', async () => {
337+
const schema = await import('./schemas/schema1');
338+
339+
await push({ db, to: schema });
340+
341+
const res1 = await push({ db, to: { ...schema, core: pgSchema('core').existing() } });
342+
expect(res1.sqlStatements).toStrictEqual([]);
343+
344+
const res2 = await push({ db, to: schema });
345+
expect(res2.sqlStatements).toStrictEqual([]);
346+
});

drizzle-kit/tests/postgres/schemas/schema1.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { eq, sql } from 'drizzle-orm';
2-
import { decimal } from 'drizzle-orm/cockroach-core';
32
import {
43
AnyPgColumn,
54
bigint,

0 commit comments

Comments
 (0)