Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.

how import SQL DDL MSSQL ? #7

Closed
CyberCode94 opened this issue Apr 21, 2020 · 4 comments
Closed

how import SQL DDL MSSQL ? #7

CyberCode94 opened this issue Apr 21, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@CyberCode94
Copy link

I cannot Import SQL DDL MSSQL, I need solution from MSSQL.
can help me ?

@dineug
Copy link
Owner

dineug commented Apr 21, 2020

DDL Parser currently relies on sql-ddl-to-json-schema, so only mysql is supported.

Instead, you can try after transformation with mysql delimitation.

MySQL syntax

CREATE TABLE users (
  id INT(11) NOT NULL AUTO_INCREMENT,
  nickname VARCHAR(255) NOT NULL,
  deleted_at TIMESTAMP NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
  updated_at TIMESTAMP,
  PRIMARY KEY (id)
) ENGINE MyISAM COMMENT 'All system users';

ALTER TABLE users ADD UNIQUE KEY unq_nick (nickname);

Example of converting mssql data type

const dataTypeMapping = [
  { mssql: "numeric", mysql: "FLOAT" },
  { mssql: "smallmoney", mysql: "FLOAT" },
  { mssql: "money", mysql: "DOUBLE" },
  { mssql: "real", mysql: "FLOAT" },
  { mssql: "datetimeoffset", mysql: "DATETIME" },
  { mssql: "datetime2", mysql: "DATETIME" },
  { mssql: "smalldatetime", mysql: "DATETIME" },
  { mssql: "nchar", mysql: "CHAR" },
  { mssql: "nvarchar", mysql: "VARCHAR" },
  { mssql: "ntext", mysql: "TEXT" },
  { mssql: "image", mysql: "BLOB" },
  { mssql: "sql_variant", mysql: "VARCHAR" },
  { mssql: "xml", mysql: "BLOB" },
  { mssql: "geography", mysql: "VARCHAR" },
];

const fs = require("fs");
const mssqlTEXT = fs.readFileSync("./mssqlDDL.sql", "utf8");

let convertText = mssqlTEXT;
convertText = convertText.replace(/GO/gi, ";");
dataTypeMapping.forEach((mapping) => {
  convertText = convertText.replace(
    new RegExp(mapping.mssql, "gi"),
    mapping.mysql
  );
});

console.log(convertText);

fs.writeFileSync("./mssqlDDLConvertDataType.sql", convertText);

@coleman-rik
Copy link

Would love to see PostgreSQL import capability here.

@dineug
Copy link
Owner

dineug commented Aug 4, 2020

SQL DDL parser is working!

I'll try my best.

dineug added a commit that referenced this issue Sep 1, 2020
@dineug dineug closed this as completed Sep 1, 2020
@dineug
Copy link
Owner

dineug commented Sep 2, 2020

Current Support Syntax Here

@dineug dineug added the enhancement New feature or request label Sep 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants