mirror of
https://github.com/getAlby/hub.git
synced 2026-08-13 12:33:39 +02:00
fix: ensure to not hit postgres parameter limit when migrating sqlite to postgres (#1511)
This commit is contained in:
parent
021f4c56bc
commit
df5e566309
1 changed files with 13 additions and 2 deletions
|
|
@ -165,8 +165,19 @@ func migrateTable[T any](from, to *gorm.DB) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if err := to.Create(data).Error; err != nil {
|
||||
return fmt.Errorf("failed to insert data: %w", err)
|
||||
// to avoid "failed to migrate transactions: failed to insert data: extended protocol limited to 65535 parameters"
|
||||
// see https://stackoverflow.com/questions/77372430/extended-protocol-limited-to-65535-parameters-golang-gorm
|
||||
// max statements is 65535
|
||||
// but it's the number of records * columns
|
||||
// to be safe, using a lower value of 1000.
|
||||
// this will fail if any table has more than 65 columns, which I doubt we will have
|
||||
max := 1000
|
||||
for i := 0; i < len(data); i += max {
|
||||
j := min(i+max, len(data))
|
||||
|
||||
if err := to.Create(data[i:j]).Error; err != nil {
|
||||
return fmt.Errorf("failed to insert data: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue