Remove defaulted id column once pkey has been changed #517
-
Hindsight is 20-20 and we should have setup our database differently at the start however, I am looking for some possible suggestions on how to handle the following scenario. We are using TimescaleDB (PostgreSQL 14.2). With this in mind we needed composite primary keys in order to make hypertables. Right now the way we have handled this was to
Okay so that is the problem above (fun one I know) but I am wondering is there a way to safely drop this |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's a hard one. Piccolo tables needs some kind of primary key, and it doesn't currently have syntax to support composite primary keys. I came across this article which might help you. It's Citus instead of Timescale, but they're similar enough. Even so, 2 billion rows still meant 20 minutes of downtime which might still be unacceptable. It's kind of a hack, but you could set class MyTable(Table):
my_column = Varchar(primary_key=True) When you run This will only work though if you have no foreign keys pointing to the table - not sure if this is the case or not. |
Beta Was this translation helpful? Give feedback.
It's a hard one. Piccolo tables needs some kind of primary key, and it doesn't currently have syntax to support composite primary keys.
I came across this article which might help you. It's Citus instead of Timescale, but they're similar enough. Even so, 2 billion rows still meant 20 minutes of downtime which might still be unacceptable.
It's kind of a hack, but you could set
primary_key=True
on one of your other columns - even though it's not an actual primary key, Piccolo will think it is, and should be happy.When you run
piccolo migrations new my_app --auto
it will generate a migration. If you run it nothing will happen, …