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

Implement option to specify any column as primary key #247

Merged
merged 3 commits into from Nov 4, 2021

Conversation

lafriks
Copy link
Contributor

@lafriks lafriks commented Nov 3, 2021

Partially fixes #244

Still need to implement this into go-rel/sql and probably adapters

@lafriks lafriks added the enhancement New feature or request label Nov 3, 2021
@codecov
Copy link

codecov bot commented Nov 3, 2021

Codecov Report

Merging #247 (1d8436f) into master (cbcbfd4) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #247   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           56        56           
  Lines         3969      3972    +3     
=========================================
+ Hits          3969      3972    +3     
Impacted Files Coverage Δ
column.go 100.00% <ø> (ø)
schema_options.go 100.00% <100.00%> (ø)
table.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cbcbfd4...1d8436f. Read the comment docs.

schema_test.go Show resolved Hide resolved
@Fs02
Copy link
Member

Fs02 commented Nov 4, 2021

what happens to generated query for each adapter when Primary is set to false?
I'm asking this because for example in mysql, AUTO_INCREMENT need to be defined as a key

@lafriks
Copy link
Contributor Author

lafriks commented Nov 4, 2021

That's really up to the developer on what to define as primary key.

Imho this would still work in MySQL:

schema.CreateTable("audit", func(t *rel.Table) {
  t.BigID("id", rel.Primary(false), rel.Required(true))
  // other fields
  t.PrimaryKey("id")
 })

that would generate:

CREATE TABLE audit (
    id BIGINT NOT NULL AUTO_INCREMENT,
    // other fields
    PRIMARY KEY (id)
);

@Fs02
Copy link
Member

Fs02 commented Nov 4, 2021

but if user doesn't specify t.PrimaryKey("id"), it'll be invalid sql? do you think we should handle that? or just let it error?

@lafriks
Copy link
Contributor Author

lafriks commented Nov 4, 2021

If user on purpose specifies Primary(false) than I don't think library should handle that as that is very database specific, so imho we just let it error

@Fs02
Copy link
Member

Fs02 commented Nov 4, 2021

agree 👍

table.go Show resolved Hide resolved
Copy link
Member

@Fs02 Fs02 left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks!!

@Fs02 Fs02 merged commit e534415 into go-rel:master Nov 4, 2021
@lafriks lafriks deleted the feat/col_primary_key branch November 4, 2021 14:24
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.

Allow to manually sepecify column as Primary column option
2 participants