Pull-request para export a Oracle (#4)

* Permito deployment en un subfolder

* Remove vercel/analytics

* Remove vercel/analytics

* Remove vercel/analytics

* Revert "Permito deployment en un subfolder"

This reverts commit e7aedc3ecf.

* Boton de oracle funciona pero no add table

* datatypes.js fixed

* export oracle funciona, falta formato adecuado

* Agregando convenciones a constraints

* Cambiando detalle de unique constraint

* Adding a test for diagram exports to oracle

* tests for constraints added

* Correccion de la funcion check

* vercel added and tests run with npm run lint

* little fixes, vercel added in datatypes and main.jsx

* Delete tatus file added by mistake

---------

Co-authored-by: Francisco-Galindo <paqui10718@gmail.com>
Co-authored-by: hansmarcus <hansmarcus14@gmail.com>
Co-authored-by: Pablo Estrada <pabloem@apache.org>
This commit is contained in:
lethalSopaper
2025-02-06 22:41:42 -06:00
committed by GitHub
parent aaf83b6f28
commit d95b86b7b5
20 changed files with 5173 additions and 345 deletions

View File

@@ -0,0 +1,54 @@
/* eslint-env jest */
import { toOracle } from "../src/utils/exportSQL/oracle.js";
import { DB } from "../src/data/constants.js";
describe("toOracle", () => {
test("test for unique index creation", () => {
const diagram = {
database: DB.ORACLE,
tables: [
{
name: "mochila",
fields: [
{
name: "mochila_id",
type: "NUMBER",
size: "10,0",
notNull: true,
primary: true,
default: "",
},
{
name: "capacidad_kg",
type: "NUMBER",
size: "2,0",
notNull: true,
default: "",
},
],
indices: [
{
name: "mochila_index_0",
fields: ["mochila_id"],
unique: true,
}
],
},
],
references: [],
};
const expectedSQL = `CREATE TABLE mochila (
\t"mochila_id" NUMBER(10,0) NOT NULL,
\t"capacidad_kg" NUMBER(2,0) NOT NULL,
\tCONSTRAINT mochila_pk PRIMARY KEY("mochila_id")
);
CREATE UNIQUE INDEX "mochila_index_0" ON mochila ("mochila_id");
`;
const result = toOracle(diagram);
expect(result.trim()).toBe(expectedSQL.trim());
});
});

62
test/oracle_c_idx.test.js Normal file
View File

@@ -0,0 +1,62 @@
/* eslint-env jest */
import { toOracle } from "../src/utils/exportSQL/oracle.js";
import { DB } from "../src/data/constants.js";
describe("toOracle", () => {
test("test for unique index creation", () => {
const diagram = {
database: DB.ORACLE,
tables: [
{
name: "mochila",
fields: [
{
name: "mochila_id",
type: "NUMBER",
size: "10,0",
notNull: true,
primary: true,
default: "",
},
{
name: "capacidad_kg",
type: "NUMBER",
size: "2,0",
notNull: true,
default: "",
},
{
name: "compartimentos",
type: "NUMBER",
size: "2,0",
notNull: true,
default: "",
},
],
indices: [
{
name: "mochila_index_0",
fields: ["capacidad_kg", "compartimentos"],
unique: true,
}
],
},
],
references: [],
};
const expectedSQL = `CREATE TABLE mochila (
\t"mochila_id" NUMBER(10,0) NOT NULL,
\t"capacidad_kg" NUMBER(2,0) NOT NULL,
\t"compartimentos" NUMBER(2,0) NOT NULL,
\tCONSTRAINT mochila_pk PRIMARY KEY("mochila_id")
);
CREATE UNIQUE INDEX "mochila_index_0" ON mochila ("capacidad_kg", "compartimentos");
`;
const result = toOracle(diagram);
expect(result.trim()).toBe(expectedSQL.trim());
});
});

46
test/oracle_chk.test.js Normal file
View File

@@ -0,0 +1,46 @@
/* eslint-env jest */
import { toOracle } from "../src/utils/exportSQL/oracle.js";
import { DB } from "../src/data/constants.js";
describe("toOracle", () => {
test("test for check constraint in any field of a table", () => {
const diagram = {
database: DB.ORACLE,
tables: [
{
name: "salon",
fields: [
{
name: "salon_id",
type: "NUMBER",
size: "10,0",
notNull: true,
primary: true,
default: "",
},
{
name: "capacidad",
type: "NUMBER",
size: "10,0",
notNull: true,
default: "",
check: "> 0",
},
],
indices: [],
},
],
references: [],
};
const expectedSQL = `CREATE TABLE salon (
\t"salon_id" NUMBER(10,0) NOT NULL,
\t"capacidad" NUMBER(10,0) NOT NULL,
\tCONSTRAINT salon_capacidad_chk CHECK("capacidad" > 0),
\tCONSTRAINT salon_pk PRIMARY KEY("salon_id")
);`;
const result = toOracle(diagram);
expect(result.trim()).toBe(expectedSQL.trim());
});
});

View File

@@ -0,0 +1,75 @@
/* eslint-env jest */
import { toOracle } from "../src/utils/exportSQL/oracle.js";
import { DB } from "../src/data/constants.js";
describe("toOracle", () => {
test("should generate correct Oracle SQL for tables with relationships", () => {
const diagram = {
database: DB.ORACLE,
tables: [
{
name: "casa",
fields: [
{
name: "id",
type: "NUMBER",
size: "10,0",
notNull: true,
unique: true,
primary: true,
default: ""
},
{
name: "xd",
type: "VARCHAR",
size: "255",
notNull: true,
default: ""
}
],
indices: []
},
{
name: "cuarto",
fields: [
{
name: "id",
type: "NUMBER",
unique: true,
primary: true,
default: ""
}
],
indices: []
}
],
references: [
{
startTableId: 0,
startFieldId: 0,
endTableId: 1,
endFieldId: 0
}
]
};
const expectedSQL = `CREATE TABLE casa (
\t"id" NUMBER(10,0) NOT NULL,
\t"xd" VARCHAR(255) NOT NULL,
\tCONSTRAINT casa_pk PRIMARY KEY("id")
);
CREATE TABLE cuarto (
\t"id" NUMBER,
\tCONSTRAINT cuarto_pk PRIMARY KEY("id")
);
ALTER TABLE casa ADD CONSTRAINT casa_id_fk
FOREIGN KEY("id") REFERENCES cuarto("id");`;
const result = toOracle(diagram);
expect(result.trim()).toBe(expectedSQL.trim());
});
});

75
test/oracle_pk_fk.test.js Normal file
View File

@@ -0,0 +1,75 @@
/* eslint-env jest */
import { toOracle } from "../src/utils/exportSQL/oracle.js";
import { DB } from "../src/data/constants.js";
describe("toOracle", () => {
test("should generate correct Oracle SQL for tables with relationships", () => {
const diagram = {
database: DB.ORACLE,
tables: [
{
name: "casa",
fields: [
{
name: "id",
type: "NUMBER",
size: "10,0",
notNull: true,
unique: true,
primary: true,
default: ""
},
{
name: "xd",
type: "VARCHAR",
size: "255",
notNull: true,
default: ""
}
],
indices: []
},
{
name: "cuarto",
fields: [
{
name: "id",
type: "NUMBER",
unique: true,
primary: true,
default: ""
}
],
indices: []
}
],
references: [
{
startTableId: 0,
startFieldId: 0,
endTableId: 1,
endFieldId: 0
}
]
};
const expectedSQL = `CREATE TABLE casa (
\t"id" NUMBER(10,0) NOT NULL,
\t"xd" VARCHAR(255) NOT NULL,
\tCONSTRAINT casa_pk PRIMARY KEY("id")
);
CREATE TABLE cuarto (
\t"id" NUMBER,
\tCONSTRAINT cuarto_pk PRIMARY KEY("id")
);
ALTER TABLE casa ADD CONSTRAINT casa_id_fk
FOREIGN KEY("id") REFERENCES cuarto("id");`;
const result = toOracle(diagram);
expect(result.trim()).toBe(expectedSQL.trim());
});
});

View File

@@ -0,0 +1,46 @@
/* eslint-env jest */
import { toOracle } from "../src/utils/exportSQL/oracle.js";
import { DB } from "../src/data/constants.js";
describe("toOracle", () => {
test("test for unique constraints", () => {
const diagram = {
database: DB.ORACLE,
tables: [
{
name: "computador",
fields: [
{
name: "computador_id",
type: "NUMBER",
size: "10,0",
notNull: true,
primary: true,
default: "",
},
{
name: "num_serie",
type: "VARCHAR2",
size: 40,
notNull: true,
unique: true,
default: "",
},
],
indices: [],
},
],
references: [],
};
const expectedSQL = `CREATE TABLE computador (
\t"computador_id" NUMBER(10,0) NOT NULL,
\t"num_serie" VARCHAR2(40) NOT NULL,
\tCONSTRAINT computador_num_serie_uk UNIQUE("num_serie"),
\tCONSTRAINT computador_pk PRIMARY KEY("computador_id")
);`;
const result = toOracle(diagram);
expect(result.trim()).toBe(expectedSQL.trim());
});
});