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

deparse altered "ALTER TABLE" statement, removed ON DELETE, ON UPDATE clauses #49

Closed
divyenduz opened this issue Oct 21, 2021 · 1 comment

Comments

@divyenduz
Copy link

Original query (with fingerprint 08ac274ed7e25268):

ALTER TABLE "Customer" ADD CONSTRAINT "FK_CustomerSupportRepId"
  FOREIGN KEY ("SupportRepId") REFERENCES "Employee" ("EmployeeId") ON DELETE NO ACTION ON UPDATE NO ACTION

Deparsed query (with fingerprint 7cd581c9cf34edae):

ALTER TABLE "Customer" ADD CONSTRAINT FK_CustomerSupportRepId FOREIGN KEY ( "SupportRepId" ) REFERENCES "Employee" ( "EmployeeId" );

To reproduce:

const fs = require('fs')
const { parse, deparse } = require('pgsql-parser');

async function main() {
    const stmts = parse(`
      ALTER TABLE "Customer" ADD CONSTRAINT "FK_CustomerSupportRepId"
  FOREIGN KEY ("SupportRepId") REFERENCES "Employee" ("EmployeeId") ON DELETE NO ACTION ON UPDATE NO ACTION
    `)
    const stmts2 = deparse(stmts[0])
    console.log(stmts2)
}

main()

Schema at https://github.com/prisma/database-schema-examples/tree/main/postgres/chinook

@pyramation
Copy link
Collaborator

those are the defaults, so they don't get printed. When I run the AST generated from the code and then to code, and back to AST, it's the same result. I'll add this snippet to the test cases and push it.

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

2 participants