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

Generate Sqlite create table comments #17198

Merged

Conversation

skalpin
Copy link
Contributor

@skalpin skalpin commented Aug 16, 2019

This only works with create table. Alter table commands do not preserve
comments.

Fixes #16820

Please check if the PR fulfills these requirements

  • The code builds and tests pass (verified by our automated build checks)
  • Commit messages follow this format
    Summary of the changes
    - Detail 1
    - Detail 2

    Fixes #bugnumber

Please review the guidelines for CONTRIBUTING.md for more details.

@bricelam bricelam self-assigned this Aug 16, 2019
@bricelam
Copy link
Contributor

bricelam commented Aug 16, 2019

Also, do we want to handle table-level comments? Unfortunately, sqlite_master won't preserve comments before the CREATE TABLE statement, so we'd have to put them inside the table definition (which I don't like):

CREATE TABLE "Person" (
    -- Represents a person

    -- The ID
    "Id" INTEGER NOT NULL
)

@bricelam
Copy link
Contributor

bricelam commented Aug 16, 2019

Hmm... another alternative I don't like:

CREATE TABLE "Person" ( -- Represents a person
    "Id" INTEGER NOT NULL, -- The ID
    "UndocumentedColumn1" TEXT,
    "UndocumentedColumn2" TEXT,
    "Name" TEXT -- The name
)

@bricelam
Copy link
Contributor

bricelam commented Aug 16, 2019

My vote: Option B; omit spaces when no columns are documented; don't preserve table-level comments.

@skalpin
Copy link
Contributor Author

skalpin commented Aug 16, 2019

I think I like this the best. If there is a table comment, there should be a line after. Then each column with a comment should have a newline before the comment.

CREATE TABLE "People" (
    -- Table Comment

    -- The ID
    "Id" INTEGER NOT NULL,
    "UndocumentedColumn1" TEXT,
    "UndocumentedColumn2" TEXT,

    -- The name
    "Name" TEXT
)

Do you like having a newline after the commented column better? like:

CREATE TABLE "People" (
    -- Table Comment

    -- The ID
    "Id" INTEGER NOT NULL,

    "UndocumentedColumn1" TEXT,
    "UndocumentedColumn2" TEXT,

    -- The name
    "Name" TEXT
)

@bricelam
Copy link
Contributor

Do you like having a newline after the commented column better?

It's how I would write it, but just putting a newline before the comment is a simpler implementation, so I'd be fine with that too.

Copy link
Contributor

@bricelam bricelam left a comment

Choose a reason for hiding this comment

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

LGTM. I'll let you decide what format we should use. ¯\(ツ)/¯ Do you think we should output table-level comments? Let me know when you're ready for me to merge it.

@skalpin skalpin force-pushed the bug/16820_Sqlite_HasComment branch from 2f53876 to 1d0a0af Compare August 17, 2019 01:23
@skalpin skalpin force-pushed the bug/16820_Sqlite_HasComment branch from 1d0a0af to da541b6 Compare August 17, 2019 19:07

private void CreateComment(MigrationCommandListBuilder builder, string comment)
{
foreach (var line in comment.Split(Environment.NewLine).Select(l => $"-- {l}"))
Copy link
Contributor

Choose a reason for hiding this comment

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

We’ve taken a bug fix for code that did this somewhere else. I think it was about Unix line endings on Windows or something. I’ll try to find that implementation so we can reuse it here.

@ajcvickers
Copy link
Member

@bricelam Remember to rebase on or cherry-pick to preview 9.

/// <summary>
/// The default single line comment prefix.
/// </summary>
protected virtual string SingleLineCommentToken { get; } = "--";
Copy link
Contributor

Choose a reason for hiding this comment

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

@ajcvickers @smitpatel I'm breaking this (moving it to the general SQL generator so it can be shared with Migrations)

@bricelam bricelam changed the base branch from master to release/3.0-preview9 August 19, 2019 19:59
skalpin and others added 2 commits August 19, 2019 12:59
- This only works with create table. Alter table commands do not
preserve comments.
- If comments are included, each column will be spaced.
- Table comments
- Column comments

Fixes dotnet#16820
@bricelam bricelam merged commit 5e79127 into dotnet:release/3.0-preview9 Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants