Skip to content

Unclear seeding behavior #3510

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

Open
sweigert opened this issue May 2, 2025 · 0 comments
Open

Unclear seeding behavior #3510

sweigert opened this issue May 2, 2025 · 0 comments

Comments

@sweigert
Copy link

sweigert commented May 2, 2025

Seeding currently does not work as expected for me.
My expectation would be that I can add data to the seed files and when I apply them on the remote they get re-executed (because their hash changes).
What actually happens, though, is that the hash gets updated but the file is ignored otherwise.
What is the purpose of this behaviour?

The issue is here:
If a seed file exists but its content (=hash) changed, it is marked as dirty here:

if hash, exists := applied[seed.Path]; exists {
// Skip seed files that already exist
if hash == seed.Hash {
continue
}
// Mark seed file as dirty
seed.Dirty = true
}

However, if it is dirty, it seems its contents are not added to the batch of changes but only the hash is updated:

cli/pkg/migration/file.go

Lines 172 to 183 in 0bfa100

// Data statements don't mutate schemas, safe to use statement cache
batch := pgx.Batch{}
if !m.Dirty {
for _, line := range lines {
batch.Queue(line)
}
}
batch.Queue(UPSERT_SEED_FILE, m.Path, m.Hash)
// No need to track version here because there are no schema changes
if err := conn.SendBatch(ctx, &batch).Close(); err != nil {
return errors.Errorf("failed to send batch: %w", err)
}

An example of my seed would be:

-- file_types has a primary key on "ext"
INSERT INTO file_types (ext, description)
VALUES
  ('zip', 'some description'),
  ('tar', 'some other description')
ON CONFLICT DO UPDATE SET description=EXCLUDED.description;

If that is my initial seed file, I can have it in git and update it as my app grows, e.g.:

-- file_types has a primary key on "ext"
INSERT INTO file_types (ext, description)
VALUES
  ('zip', 'a better description'),
  ('tar', 'some other description'),
  ('xz', 'a much better description')
ON CONFLICT DO UPDATE SET description=EXCLUDED.description;

Now one row will be updated, one ignored and one inserted.

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

No branches or pull requests

1 participant