Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(postgres): default datetime/timestamp precision setting added #5311

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

fabis94
Copy link

@fabis94 fabis94 commented Aug 24, 2022

closes #5308

@fabis94
Copy link
Author

fabis94 commented Aug 24, 2022

I dunno why, but locally i'm getting random files that I never touched being changed and added to commits: lib/.gitignore and dialects/index.js

I've removed them (hence the multiple commits), but if I try to rebase the branch or anything they appear again. Is this some magic configured together with git hooks?

} = require('../util/knex-instance-provider');

describe('PostgreSQL dialect', () => {
const dbs = getAllDbs().filter((db) => db === Db.PostgresSQL);
Copy link
Collaborator

@kibertoad kibertoad Aug 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so uh, why do you get a list and filter it down to a single value, instead of just starting with that single value?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I was mostly just repeating this procedure the same way it was done in other integration tests

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kibertoad so should I just fix this part and then this is ready for merge?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's try enabling tests for CockroachDB as well and see if that would also pass

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kibertoad I've refactored the tests to also test CockroachDb as well. The column alteration test has to be skipped though, because apparently CockroachDB doesn't support altering columns?

Considering that I don't know anything about CockroachDb, that this PR isn't even meant for it and I'm having to deal with CockroachDB specific issues now I'd prefer it if we can just release this feature as is and if anyone needs something extra for CockroachDB, they can always submit another PR.

@coveralls
Copy link

coveralls commented Sep 1, 2022

Coverage Status

coverage: 92.789% (+0.002%) from 92.787%
when pulling 7ab78fa on fabis94:fabians/pg-default-precision
into 6243f6c on knex:master.

lib/.gitignore Outdated
@@ -7,4 +7,4 @@
**/*.js.map

# Do not include .js files from .ts files
dialects\index.js
dialects/index.js
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is done automatically by one of the npm scripts, in fact I can't even get rid of this change cause it gets added back every time I revert it

@fabis94
Copy link
Author

fabis94 commented Sep 18, 2022

@kibertoad i'd appreciate it if we could get this merged sometime soon 🙌

@fabis94
Copy link
Author

fabis94 commented Sep 22, 2022

@kibertoad I see some tests are failing, but the failures don't make sense to me - There are some connection refused errors and errors in tests that don't really seem to have anything to do with my changes, so could it be a test runner issue as well? The tests did run through successfully on my end

@OlivierCavadenti
Copy link
Collaborator

@kibertoad I see some tests are failing, but the failures don't make sense to me - There are some connection refused errors and errors in tests that don't really seem to have anything to do with my changes, so could it be a test runner issue as well? The tests did run through successfully on my end

I will check the tests later, but it's seems you do some strange init of DB instances...

@fabis94
Copy link
Author

fabis94 commented Sep 23, 2022

@kibertoad I see some tests are failing, but the failures don't make sense to me - There are some connection refused errors and errors in tests that don't really seem to have anything to do with my changes, so could it be a test runner issue as well? The tests did run through successfully on my end

I will check the tests later, but it's seems you do some strange init of DB instances...

Thank you! This is a new & foreign repo for me, so I just tried to look at how other tests are written to write mine

@fabis94
Copy link
Author

fabis94 commented Sep 30, 2022

@OlivierCavadenti @kibertoad Hi, any news on this? If there are any changes I need to do, let me know, but please also provide me some providers on the correct way to do things, cause this repo is new to me

@fabis94
Copy link
Author

fabis94 commented Oct 10, 2022

Anything I can do to push this through quicker? I'm fine making changes, if anyone can give me pointers :)

Copy link
Member

@rluvaton rluvaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a few comments, great job!
let's resolve those and get this thing merged

@kibertoad what about docs update?

@fabis94
Copy link
Author

fabis94 commented Dec 5, 2023

@rluvaton I've resolved both of the issues you brought up

Copy link
Member

@rluvaton rluvaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kibertoad can you please merge

@kibertoad
Copy link
Collaborator

@fabis94 Tests are failing

@fabis94
Copy link
Author

fabis94 commented Dec 7, 2023

@kibertoad @rluvaton The test failures don't make sense to me, it's a bunch of "Error: connect ECONNREFUSED ::1:26257" errors, and I didn't change any of the connection settings so it doesn't feel very related 🤔 https://github.com/knex/knex/actions/runs/7098240971/job/19422356671

@kibertoad
Copy link
Collaborator

@fabis94 Only new tests are failing, though. See the end of logs at https://github.com/knex/knex/actions/runs/7098240971/job/19422352541?pr=5311

Are they passing locally for you?

});

// cockroachdb doesn't support altering columns at this point in time? https://github.com/cockroachdb/cockroach/issues/49329
it('if default datetime precision specified, it gets used when altering datetime/timestamp fields', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('if default datetime precision specified, it gets used when altering datetime/timestamp fields', async () => {
it('if default datetime precision specified, it gets used when altering datetime/timestamp fields', async function() {

@rluvaton
Copy link
Member

rluvaton commented Dec 7, 2023

It fails for me as well

@fabis94
Copy link
Author

fabis94 commented Dec 11, 2023

@rluvaton @kibertoad This project doesn't exactly have the nicest contributor onboarding experience, the contributor docs are lacking and I was never able to get all of the tests working even on the main branch!

So yes, I do see test failures locally, but many of them seem unrelated to this ticket and I'd appreciate some help here considering that I don't know this project very well.

I fixed the issue @rluvaton brought up, but I'm still getting test failures locally:

 1) CLI tests
       knexfile
         knexfile resolution
           --cwd is NOT specified
             but --knexfile is specified
               changes the process's cwd to the directory that contains the knexfile:
     Error: Expected output to include "Working directory changed to ~/Code/random/knex/test/jake-util/knexfile-relative", but it was actually "Working directory changed to ~/Code/random/knex/test/jake-util/knexfile-relative
sqlite does not support inserting default values. Set the `useNullAsDefault` flag to hide this warning. (see docs https://knexjs.org/guide/query-builder.html#insert).
Batch 1 run: 2 migrations
"
      at new AssertionError (node_modules/cli-testlab/lib/AssertionError.ts:3:5)
      at assertOutput (node_modules/cli-testlab/lib/execution-test-helper.ts:71:14)
      at Exec.<anonymous> (node_modules/cli-testlab/lib/execution-test-helper.ts:149:9)
      at Exec.emit (node:events:513:28)
      at ChildProcess.<anonymous> (node_modules/cli-testlab/node_modules/jake/lib/utils/index.js:230:20)
      at ChildProcess.emit (node:events:513:28)
      at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)

  2) CLI tests
       knexfile
         knexfile resolution
           --cwd is NOT specified
             but --knexfile is specified
               and the knexfile itself resolves paths relative to process.cwd()
                 changes the process's cwd to the directory that contains the knexfile before opening the knexfile:
     Error: Expected output to include "Working directory changed to ~/Code/random/knex/test/jake-util/knexfile-relative", but it was actually "Working directory changed to ~/Code/random/knex/test/jake-util/knexfile-relative
sqlite does not support inserting default values. Set the `useNullAsDefault` flag to hide this warning. (see docs https://knexjs.org/guide/query-builder.html#insert).
Batch 1 run: 2 migrations
"
      at new AssertionError (node_modules/cli-testlab/lib/AssertionError.ts:3:5)
      at assertOutput (node_modules/cli-testlab/lib/execution-test-helper.ts:71:14)
      at Exec.<anonymous> (node_modules/cli-testlab/lib/execution-test-helper.ts:149:9)
      at Exec.emit (node:events:513:28)
      at ChildProcess.<anonymous> (node_modules/cli-testlab/node_modules/jake/lib/utils/index.js:230:20)
      at ChildProcess.emit (node:events:513:28)
      at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)

  3) PostgreSQL & Cockroach DB
       postgres
         when schema building
           with default datetime precision specified
             if default datetime precision specified, it gets used when creating datetime/timestamp fields:
     error: password authentication failed for user "testuser"
      at Parser.parseErrorMessage (node_modules/pg-protocol/src/parser.ts:369:69)
      at Parser.handlePacket (node_modules/pg-protocol/src/parser.ts:188:21)
      at Parser.parse (node_modules/pg-protocol/src/parser.ts:103:30)
      at Socket.<anonymous> (node_modules/pg-protocol/src/index.ts:7:48)
      at Socket.emit (node:events:513:28)
      at addChunk (node:internal/streams/readable:324:12)
      at readableAddChunk (node:internal/streams/readable:297:9)
      at Socket.Readable.push (node:internal/streams/readable:234:10)
      at TCP.onStreamRead (node:internal/stream_base_commons:190:23)

  4) PostgreSQL & Cockroach DB
       cockroachdb
         when schema building
           with default datetime precision specified
             if default datetime precision specified, it gets used when creating datetime/timestamp fields:
     error: create table "default_datetime_precision_test_1702284324708" ("timestamp_field" timestamptz(2), "datetime_field" timestamptz(2), "created_at" timestamptz(2), "updated_at" timestamptz(2)) - no database or schema specified
      at Parser.parseErrorMessage (node_modules/pg-protocol/src/parser.ts:369:69)
      at Parser.handlePacket (node_modules/pg-protocol/src/parser.ts:188:21)
      at Parser.parse (node_modules/pg-protocol/src/parser.ts:103:30)
      at Socket.<anonymous> (node_modules/pg-protocol/src/index.ts:7:48)
      at Socket.emit (node:events:513:28)
      at addChunk (node:internal/streams/readable:324:12)
      at readableAddChunk (node:internal/streams/readable:297:9)
      at Socket.Readable.push (node:internal/streams/readable:234:10)
      at TCP.onStreamRead (node:internal/stream_base_commons:190:23)

  5) PostgreSQL & Cockroach DB
       cockroachdb
         when schema building
           with default datetime precision specified
             if default datetime precision specified, it gets used when altering datetime/timestamp fields:
     error: create table "default_datetime_precision_test_1702284324713" ("timestamp_field" timestamptz(5), "datetime_field" timestamptz(5)) - no database or schema specified
      at Parser.parseErrorMessage (node_modules/pg-protocol/src/parser.ts:369:69)
      at Parser.handlePacket (node_modules/pg-protocol/src/parser.ts:188:21)
      at Parser.parse (node_modules/pg-protocol/src/parser.ts:103:30)
      at Socket.<anonymous> (node_modules/pg-protocol/src/index.ts:7:48)
      at Socket.emit (node:events:513:28)
      at addChunk (node:internal/streams/readable:324:12)
      at readableAddChunk (node:internal/streams/readable:297:9)
      at Socket.Readable.push (node:internal/streams/readable:234:10)
      at TCP.onStreamRead (node:internal/stream_base_commons:190:23)

@rluvaton
Copy link
Member

Thank you for the feedback, do you mind opening an issue with all the thing you wish was better?

Are the with default datetime precision specified tests are failing in master as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable the configuring of the default precision for timestamp/datetime fields
5 participants