Skip to content
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

Add sequence support #35

Merged
merged 4 commits into from
Jul 7, 2023
Merged

Add sequence support #35

merged 4 commits into from
Jul 7, 2023

Conversation

bplunkett-stripe
Copy link
Collaborator

Description

Add sequence (and serial support). A little gross because we all columns ops are grouped in the same add/alter block.

Motivation

#34

Testing

Tested via acceptance tests

}

func (o oldAndNew[S]) GetOld() S {
return o.new
return o.old
Copy link
Collaborator Author

@bplunkett-stripe bplunkett-stripe Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crazy bug. I'm shocked this was working, but I'm guessing it's because we only use this function in a few places

@bplunkett-stripe bplunkett-stripe force-pushed the bplunkett/serial-suppport branch from 977d5cd to ecdb0c3 Compare June 28, 2023 17:23
@bplunkett-stripe bplunkett-stripe force-pushed the bplunkett/serial-suppport branch from ecdb0c3 to 8538e24 Compare June 28, 2023 17:33
Copy link
Collaborator

@alexaub-stripe alexaub-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Comments are worth looking at so requesting changes, but this largely lgtm

internal/migration_acceptance_tests/sequence_cases_test.go Outdated Show resolved Hide resolved
internal/queries/queries.sql Show resolved Hide resolved
SequenceOwner struct {
TableName SchemaQualifiedName
// TableUnescapedName is a hackaround until we switch over Tables ot use fully-qualified, escaped names
TableUnescapedName string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: Add a deprecated docstring to reduce further usages? Not sure if this would actually work how we want it https://stackoverflow.com/questions/7849663/how-do-you-mark-code-as-deprecated-in-go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue stems from using the unescaped name in the Table schema object. I don't think marking the field as deprecated indicates where the problem actually arises from (the Table schema object's logic for generating name). I do have a ticket to fix this though!

pkg/diff/sql_generator.go Show resolved Hide resolved
if !cmp.Equal(diff.old, diff.new) {
// Technically, we could support altering expression, but I don't see the use case for it. it would require more test
// cases than forceReadding it, and I'm not convinced it unlocks any functionality
return nil, fmt.Errorf("altering check constraint to resolve the following diff %s: %w", cmp.Diff(diff.old, diff.new), ErrNotImplemented)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error appears to refer to check constraints and should refer to sequence alters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot!

pkg/diff/sql_generator.go Show resolved Hide resolved
return []Statement{{
DDL: fmt.Sprintf("DROP SEQUENCE %s", seq.GetFQEscapedName()),
Timeout: statementTimeoutDefault,
Hazards: hazards,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping a sequence will destroy state (the internal value), so there should be a hazard for that right? This should trigger on recreates in the absence of alters.

pkg/diff/sql_generator.go Show resolved Hide resolved
alexaub-stripe
alexaub-stripe previously approved these changes Jul 7, 2023
var hazards []MigrationHazard
hazards := []MigrationHazard{{
Type: MigrationHazardTypeDeletesData,
Message: "By deleting a sequence, its state will be permanently lost",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe replace "its state" with "its current value" to be specific?

@bplunkett-stripe bplunkett-stripe merged commit a0d7b84 into main Jul 7, 2023
@bplunkett-stripe bplunkett-stripe deleted the bplunkett/serial-suppport branch July 7, 2023 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants