Comments (5)
you just mark in the changelog that this is breaking change and eventually bump major version.
Great idea actually!
from pglock.
Hi @acim - thanks for opening this issue and the PR.
At first, I decided to add an non-idempotent CreateTable
method because I wanted a clear signal that the table was already there. CreateTable
will indeed error if a table with the same name is present, which I believe to be more beneficial for two problems that hit me along the way.
-
If the structure of the table changes, you won't get a silent failure.
-
If the table name you chose collides with the use of the table by another application or library, you won't get a silent failure.
It is quite tempting to believe that the typical case of pglock is somewhere in a standalone world. My experience so far has shown me that to not be the case, pglock
usually lives inside a larger application and sharing some database context with it.
Therefore, if anything, I'd like to see the CreateTable
go away instead of being made smarter.
With all that said, you are not the first one who proposes this idea, which is starting to make me believe it is about time to think of a v2 for pglock. You could refer to further reasoning in: #28
from pglock.
I considered your reasoning before reporting this issue, but this is kind of choosing between two bad solutions. If you drop CreateTable then everyone has to create the table somehow else, either manually or by adding migration. Even in that case the problem of changing the table schema would remain.
The only automatic way would be to read the information_schema and find out if the table with correct schema is there or not.
Or maybe to add version field in the table and keep it there forever (in each schema change). Then you could find out if the schema version is fine or not and eventually panic (yes, panic is very bad in libraries) or something. I see that this is quite difficult topic even though it looks easy.
from pglock.
If you drop CreateTable then everyone has to create the table somehow else, either manually or by adding migration.
And I think that's fine. It is for the consumer of this package to decide how the database should be operated, not the library itself. I added a piece of sugar that is being misused quite frequently. For some applications, hot DB changes might be fine, but for others it might not. CreateTable
offers a tool that is hard to wield correctly.
Even in that case the problem of changing the table schema would remain.
You are right. The problem remains but it would not be pglock's responsibility any longer.
The only automatic way would be to read the information_schema and find out if the table with correct schema is there or not.
And perhaps the more fundamental question is why it needs to be automatic in the first place.
I see that this is quite difficult topic even though it looks easy.
I agree. And because of the Go 1 compatibility promise, I can't do a lot except trying to not make the situation any worse or much different than what it currently is.
from pglock.
You are right. The problem remains but it would not be pglock's responsibility any longer.
Well, in case you have to change the schema any time in the future, you just mark in the changelog that this is breaking change and eventually bump major version. I mean it would be nice to inform users about this so that they can't miss it. :D
from pglock.
Related Issues (20)
- Lock not marked as released when heartbeat cannot be sent HOT 3
- relation "locks" does not exist HOT 3
- Support for pgx HOT 2
- SQLSTATE 400001 error on multiple boxes trying to acquire the same named lock HOT 6
- ERROR: could not serialize access due to XXX (SQLSTATE 40001) HOT 7
- Question: dealing with old locks HOT 2
- Solve CreateTable Conundrum
- Concurrent lock creation with different names leads to deadlock while releasing the lock
- Cancelled heartbeat causes release failures HOT 4
- Thoughts on Supporting GetAllLocksMetadata HOT 3
- Add Table schema in README HOT 1
- Errors while acquiring/releasing locks HOT 16
- Heartbeat not retried in case of errors HOT 1
- Enable Linters
- Introduce configurable logging levels HOT 3
- Create Sequence Fails HOT 3
- Support for `pgxpool`? HOT 5
- `TestFailIfLocked` doesn't finish when used with `pgxpool` HOT 1
- Don't log missed heartbeat as error when context is canceled HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pglock.