eisen-oxid / thermit

An exciting and inspiring messenger written in Rust 🦀 ✉️
MIT License
3 stars 0 forks source link

Add created and updated dates for user, rooms, rooms_users #43

Closed frcroth closed 3 years ago

frcroth commented 3 years ago

Closes #26. Dates are automatically set to the current date on creation, updated date is automatically set on update statements.

Unfortunately I can not run the tests locally with the new 2 database setup.

sirkrypt0 commented 3 years ago

Closes #26. Dates are automatically set to the current date on creation, updated date is automatically set on update statements.

Unfortunately I can not run the tests locally with the new 2 database setup.

Why can't you run the tests locally?

sirkrypt0 commented 3 years ago

Closes #26. Dates are automatically set to the current date on creation, updated date is automatically set on update statements.

Unfortunately I can not run the tests locally with the new 2 database setup.

Why can't you run the tests locally?

Does the procedure described here not work?

frcroth commented 3 years ago

I added a test that should not fail (the behavior works in production) but fails.

frcroth commented 3 years ago

Well if you @sirkrypt0 have any idea why the test fails, I'm happy to change this. It seems the trigger is not triggered in the test database for some reason. Tried debugging this but to no avail.

sirkrypt0 commented 3 years ago

Well if you @sirkrypt0 have any idea why the test fails, I'm happy to change this. It seems the trigger is not triggered in the test database for some reason. Tried debugging this but to no avail.

The database connection in the tests does never commit the changes to the database directly. This might be the issue here, as the database would only fill the columns once the data is committed.

sirkrypt0 commented 3 years ago

Well if you @sirkrypt0 have any idea why the test fails, I'm happy to change this. It seems the trigger is not triggered in the test database for some reason. Tried debugging this but to no avail.

The database connection in the tests does never commit the changes to the database directly. This might be the issue here, as the database would only fill the columns once the data is committed.

I did some research and think this is actually not the problem here. The triggers should run once the event, which is an update in this case, fires, regardless if there is a transaction or not.

sirkrypt0 commented 3 years ago

The trigger is executed correctly. This can be tested by changing the last_upd_trig() to also change the username like NEW.username := 'updated';. Running the test afterwards correctly changes the username. The problem is, that current_timestamp returns the current date and time with time zone, which is the time when the transaction starts. All database operations in a single test run in a single transaction, thus the current_timestamp is the same for all operations on a test connection.