mirror of
https://github.com/knex/knex.git
synced 2025-12-28 23:48:58 +00:00
Fixing posgres datetime and timestamp column created with wrong format (#4578)
This commit is contained in:
parent
c335fda657
commit
55eadcf7ad
@ -71,10 +71,10 @@ class ColumnCompiler_PG extends ColumnCompiler {
|
||||
} else {
|
||||
useTz = !withoutTz;
|
||||
}
|
||||
useTz = typeof useTz === 'boolean' ? useTz : true;
|
||||
precision = precision ? '(' + precision + ')' : '';
|
||||
|
||||
return `${useTz ? 'timestamptz' : 'timestamp'}${
|
||||
precision ? '(' + precision + ')' : ''
|
||||
}`;
|
||||
return `${useTz ? 'timestamptz' : 'timestamp'}${precision}`;
|
||||
}
|
||||
|
||||
timestamp(withoutTz = false, precision) {
|
||||
@ -84,10 +84,10 @@ class ColumnCompiler_PG extends ColumnCompiler {
|
||||
} else {
|
||||
useTz = !withoutTz;
|
||||
}
|
||||
useTz = typeof useTz === 'boolean' ? useTz : true;
|
||||
precision = precision ? '(' + precision + ')' : '';
|
||||
|
||||
return `${useTz ? 'timestamptz' : 'timestamp'}${
|
||||
precision ? '(' + precision + ')' : ''
|
||||
}`;
|
||||
return `${useTz ? 'timestamptz' : 'timestamp'}${precision}`;
|
||||
}
|
||||
|
||||
// Modifiers:
|
||||
|
||||
@ -1155,6 +1155,19 @@ describe('PostgreSQL SchemaBuilder', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('adding default datetime', () => {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
.table('users', (table) => {
|
||||
table.datetime('foo');
|
||||
})
|
||||
.toSQL();
|
||||
equal(1, tableSql.length);
|
||||
expect(tableSql[0].sql).to.equal(
|
||||
'alter table "users" add column "foo" timestamptz'
|
||||
);
|
||||
});
|
||||
|
||||
it('adding timestamp with timezone', () => {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
@ -1168,6 +1181,19 @@ describe('PostgreSQL SchemaBuilder', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('adding datetime with timezone', () => {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
.table('users', (table) => {
|
||||
table.datetime('foo', false);
|
||||
})
|
||||
.toSQL();
|
||||
equal(1, tableSql.length);
|
||||
expect(tableSql[0].sql).to.equal(
|
||||
'alter table "users" add column "foo" timestamptz'
|
||||
);
|
||||
});
|
||||
|
||||
it('adding timestamp without timezone', () => {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
@ -1181,6 +1207,19 @@ describe('PostgreSQL SchemaBuilder', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('adding datetime without timezone', () => {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
.table('users', (table) => {
|
||||
table.datetime('foo', true);
|
||||
})
|
||||
.toSQL();
|
||||
equal(1, tableSql.length);
|
||||
expect(tableSql[0].sql).to.equal(
|
||||
'alter table "users" add column "foo" timestamp'
|
||||
);
|
||||
});
|
||||
|
||||
it('adding timestamp with precision', () => {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
@ -1194,6 +1233,19 @@ describe('PostgreSQL SchemaBuilder', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('adding datetime with precision', () => {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
.table('users', (table) => {
|
||||
table.datetime('foo', undefined, 3);
|
||||
})
|
||||
.toSQL();
|
||||
equal(1, tableSql.length);
|
||||
expect(tableSql[0].sql).to.equal(
|
||||
'alter table "users" add column "foo" timestamptz(3)'
|
||||
);
|
||||
});
|
||||
|
||||
it('adding timestamp with options object', () => {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
@ -1207,6 +1259,32 @@ describe('PostgreSQL SchemaBuilder', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('adding timestamp with options object but no timestamp', () => {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
.table('users', (table) => {
|
||||
table.timestamp('foo', { precision: 3 });
|
||||
})
|
||||
.toSQL();
|
||||
equal(1, tableSql.length);
|
||||
expect(tableSql[0].sql).to.equal(
|
||||
'alter table "users" add column "foo" timestamptz(3)'
|
||||
);
|
||||
});
|
||||
|
||||
it('adding timestamp with empty options object', () => {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
.table('users', (table) => {
|
||||
table.timestamp('foo', {});
|
||||
})
|
||||
.toSQL();
|
||||
equal(1, tableSql.length);
|
||||
expect(tableSql[0].sql).to.equal(
|
||||
'alter table "users" add column "foo" timestamptz'
|
||||
);
|
||||
});
|
||||
|
||||
it('adding datetime with options object', () => {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
@ -1220,6 +1298,32 @@ describe('PostgreSQL SchemaBuilder', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('adding datetime with options object but no timestamp', () => {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
.table('users', (table) => {
|
||||
table.datetime('foo', { precision: 3 });
|
||||
})
|
||||
.toSQL();
|
||||
equal(1, tableSql.length);
|
||||
expect(tableSql[0].sql).to.equal(
|
||||
'alter table "users" add column "foo" timestamptz(3)'
|
||||
);
|
||||
});
|
||||
|
||||
it('adding datetime with empty options object', () => {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
.table('users', (table) => {
|
||||
table.datetime('foo', {});
|
||||
})
|
||||
.toSQL();
|
||||
equal(1, tableSql.length);
|
||||
expect(tableSql[0].sql).to.equal(
|
||||
'alter table "users" add column "foo" timestamptz'
|
||||
);
|
||||
});
|
||||
|
||||
it('adding timestamps', () => {
|
||||
tableSql = client
|
||||
.schemaBuilder()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user