diff --git a/CHANGELOG.md b/CHANGELOG.md index 6876c5a4d..cd7d2bb36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -318,7 +318,7 @@ Builds: - FIXED: Creating SQLite autoincrement column - FIXED: Better error reporting from exports/import/dulicator - CHANGED: Optimalizede OracleDB analysing algorithm -- ADDED: Mutli column filter for perspectives +- ADDED: Multi column filter for perspectives - FIXED: Fixed some scenarios using tables from different DBs - FIXED: Sessions with long-running queries are not killed diff --git a/e2e-tests/cypress.config.js b/e2e-tests/cypress.config.js index e4f88959f..403ed02d9 100644 --- a/e2e-tests/cypress.config.js +++ b/e2e-tests/cypress.config.js @@ -39,6 +39,9 @@ module.exports = defineConfig({ case 'team': serverProcess = exec('yarn start:team'); break; + case 'multi-sql': + serverProcess = exec('yarn start:multi-sql'); + break; } await waitOn({ resources: ['http://localhost:3000'] }); diff --git a/e2e-tests/cypress/e2e/multi-sql.js b/e2e-tests/cypress/e2e/multi-sql.js new file mode 100644 index 000000000..055ee57f4 --- /dev/null +++ b/e2e-tests/cypress/e2e/multi-sql.js @@ -0,0 +1,16 @@ +Cypress.on('uncaught:exception', (err, runnable) => { + // if the error message matches the one about WorkerGlobalScope importScripts + if (err.message.includes("Failed to execute 'importScripts' on 'WorkerGlobalScope'")) { + // return false to let Cypress know we intentionally want to ignore this error + return false; + } + // otherwise let Cypress throw the error +}); + +beforeEach(() => { + cy.visit('http://localhost:3000'); + cy.viewport(1250, 900); +}); + +describe('Data browser data', () => { +}); diff --git a/e2e-tests/data/my-guitar-shop/addresses.jsonl b/e2e-tests/data/my-guitar-shop/addresses.jsonl new file mode 100644 index 000000000..709134ddb --- /dev/null +++ b/e2e-tests/data/my-guitar-shop/addresses.jsonl @@ -0,0 +1,13 @@ +{"__isStreamHeader":true,"pureName":"addresses","tableRowCount":"12","tableEngine":"InnoDB","objectComment":"","modifyDate":"2025-02-03 02:56:32","objectId":"addresses","contentHash":"2025-02-03 02:56:32","columns":[{"notNull":true,"autoIncrement":true,"columnName":"address_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"customer_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"line1","columnComment":"","dataType":"varchar(60)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":false,"autoIncrement":false,"columnName":"line2","columnComment":"","dataType":"varchar(60)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"city","columnComment":"","dataType":"varchar(40)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"state","columnComment":"","dataType":"varchar(2)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"zip_code","columnComment":"","dataType":"varchar(10)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"phone","columnComment":"","dataType":"varchar(12)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"disabled","columnComment":"","dataType":"tinyint","defaultValue":"0","isUnsigned":false,"isZerofill":false}],"primaryKey":{"constraintName":"PRIMARY","pureName":"addresses","constraintType":"primaryKey","columns":[{"columnName":"address_id"}]},"foreignKeys":[{"constraintName":"addresses_fk_customers","constraintType":"foreignKey","pureName":"addresses","refTableName":"customers","updateAction":"NO ACTION","deleteAction":"NO ACTION","columns":[{"columnName":"customer_id","refColumnName":"customer_id"}]}],"indexes":[{"constraintName":"addresses_fk_customers","indexType":"BTREE","isUnique":false,"columns":[{"columnName":"customer_id","isDescending":0}]}],"uniques":[],"engine":"mysql@dbgate-plugin-mysql"} +{"address_id":1,"customer_id":1,"line1":"100 East Ridgewood Ave.","line2":"","city":"Paramus","state":"NJ","zip_code":"07652","phone":"201-653-4472","disabled":0} +{"address_id":2,"customer_id":1,"line1":"21 Rosewood Rd.","line2":"","city":"Woodcliff Lake","state":"NJ","zip_code":"07677","phone":"201-653-4472","disabled":0} +{"address_id":3,"customer_id":2,"line1":"16285 Wendell St.","line2":"","city":"Omaha","state":"NE","zip_code":"68135","phone":"402-896-2576","disabled":0} +{"address_id":4,"customer_id":3,"line1":"19270 NW Cornell Rd.","line2":"","city":"Beaverton","state":"OR","zip_code":"97006","phone":"503-654-1291","disabled":0} +{"address_id":5,"customer_id":4,"line1":"186 Vermont St.","line2":"Apt. 2","city":"San Francisco","state":"CA","zip_code":"94110","phone":"415-292-6651","disabled":0} +{"address_id":6,"customer_id":4,"line1":"1374 46th Ave.","line2":"","city":"San Francisco","state":"CA","zip_code":"94129","phone":"415-292-6651","disabled":0} +{"address_id":7,"customer_id":5,"line1":"6982 Palm Ave.","line2":"","city":"Fresno","state":"CA","zip_code":"93711","phone":"559-431-2398","disabled":0} +{"address_id":8,"customer_id":6,"line1":"23 Mountain View St.","line2":"","city":"Denver","state":"CO","zip_code":"80208","phone":"303-912-3852","disabled":0} +{"address_id":9,"customer_id":7,"line1":"7361 N. 41st St.","line2":"Apt. B","city":"New York","state":"NY","zip_code":"10012","phone":"212-335-2093","disabled":0} +{"address_id":10,"customer_id":7,"line1":"3829 Broadway Ave.","line2":"Suite 2","city":"New York","state":"NY","zip_code":"10012","phone":"212-239-1208","disabled":0} +{"address_id":11,"customer_id":8,"line1":"2381 Buena Vista St.","line2":"","city":"Los Angeles","state":"CA","zip_code":"90023","phone":"213-772-5033","disabled":0} +{"address_id":12,"customer_id":8,"line1":"291 W. Hollywood Blvd.","line2":"","city":"Los Angeles","state":"CA","zip_code":"90024","phone":"213-391-2938","disabled":0} diff --git a/e2e-tests/data/my-guitar-shop/addresses.table.yaml b/e2e-tests/data/my-guitar-shop/addresses.table.yaml new file mode 100644 index 000000000..13481046e --- /dev/null +++ b/e2e-tests/data/my-guitar-shop/addresses.table.yaml @@ -0,0 +1,46 @@ +name: addresses +columns: + - name: address_id + type: int + default: null + autoIncrement: true + notNull: true + - name: customer_id + type: int + default: null + notNull: true + references: customers + - name: line1 + type: varchar(60) + default: null + notNull: true + - name: line2 + type: varchar(60) + default: null + - name: city + type: varchar(40) + default: null + notNull: true + - name: state + type: varchar(2) + default: null + notNull: true + - name: zip_code + type: varchar(10) + default: null + notNull: true + - name: phone + type: varchar(12) + default: null + notNull: true + - name: disabled + type: int + default: 0 + notNull: true +primaryKey: + - address_id +indexes: + - name: addresses_fk_customers + unique: false + columns: + - customer_id diff --git a/e2e-tests/data/my-guitar-shop/administrators.jsonl b/e2e-tests/data/my-guitar-shop/administrators.jsonl new file mode 100644 index 000000000..02e8233a1 --- /dev/null +++ b/e2e-tests/data/my-guitar-shop/administrators.jsonl @@ -0,0 +1,4 @@ +{"__isStreamHeader":true,"pureName":"administrators","tableRowCount":"3","tableEngine":"InnoDB","objectComment":"","modifyDate":"2025-02-03 02:56:33","objectId":"administrators","contentHash":"2025-02-03 02:56:33","columns":[{"notNull":true,"autoIncrement":true,"columnName":"admin_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"email_address","columnComment":"","dataType":"varchar(255)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"password","columnComment":"","dataType":"varchar(255)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"first_name","columnComment":"","dataType":"varchar(255)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"last_name","columnComment":"","dataType":"varchar(255)","defaultValue":null,"isUnsigned":false,"isZerofill":false}],"primaryKey":{"constraintName":"PRIMARY","pureName":"administrators","constraintType":"primaryKey","columns":[{"columnName":"admin_id"}]},"foreignKeys":[],"indexes":[],"uniques":[],"engine":"mysql@dbgate-plugin-mysql"} +{"admin_id":1,"email_address":"admin@myguitarshop.com","password":"6a718fbd768c2378b511f8249b54897f940e9022","first_name":"Admin","last_name":"User"} +{"admin_id":2,"email_address":"joel@murach.com","password":"971e95957d3b74d70d79c20c94e9cd91b85f7aae","first_name":"Joel","last_name":"Murach"} +{"admin_id":3,"email_address":"mike@murach.com","password":"3f2975c819cefc686282456aeae3a137bf896ee8","first_name":"Mike","last_name":"Murach"} diff --git a/e2e-tests/data/my-guitar-shop/administrators.table.yaml b/e2e-tests/data/my-guitar-shop/administrators.table.yaml new file mode 100644 index 000000000..121ff0b8b --- /dev/null +++ b/e2e-tests/data/my-guitar-shop/administrators.table.yaml @@ -0,0 +1,25 @@ +name: administrators +columns: + - name: admin_id + type: int + default: null + autoIncrement: true + notNull: true + - name: email_address + type: varchar(255) + default: null + notNull: true + - name: password + type: varchar(255) + default: null + notNull: true + - name: first_name + type: varchar(255) + default: null + notNull: true + - name: last_name + type: varchar(255) + default: null + notNull: true +primaryKey: + - admin_id diff --git a/e2e-tests/data/my-guitar-shop/categories.jsonl b/e2e-tests/data/my-guitar-shop/categories.jsonl new file mode 100644 index 000000000..cf5ef1405 --- /dev/null +++ b/e2e-tests/data/my-guitar-shop/categories.jsonl @@ -0,0 +1,5 @@ +{"__isStreamHeader":true,"pureName":"categories","tableRowCount":"4","tableEngine":"InnoDB","objectComment":"","modifyDate":"2025-02-03 02:56:32","objectId":"categories","contentHash":"2025-02-03 02:56:32","columns":[{"notNull":true,"autoIncrement":true,"columnName":"category_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"category_name","columnComment":"","dataType":"varchar(255)","defaultValue":null,"isUnsigned":false,"isZerofill":false}],"primaryKey":{"constraintName":"PRIMARY","pureName":"categories","constraintType":"primaryKey","columns":[{"columnName":"category_id"}]},"foreignKeys":[],"indexes":[],"uniques":[{"constraintName":"category_name","columns":[{"columnName":"category_name"}]}],"engine":"mysql@dbgate-plugin-mysql"} +{"category_id":2,"category_name":"Basses"} +{"category_id":3,"category_name":"Drums"} +{"category_id":1,"category_name":"Guitars"} +{"category_id":4,"category_name":"Keyboards"} diff --git a/e2e-tests/data/my-guitar-shop/categories.table.yaml b/e2e-tests/data/my-guitar-shop/categories.table.yaml new file mode 100644 index 000000000..6ad63bdc2 --- /dev/null +++ b/e2e-tests/data/my-guitar-shop/categories.table.yaml @@ -0,0 +1,13 @@ +name: categories +columns: + - name: category_id + type: int + default: null + autoIncrement: true + notNull: true + - name: category_name + type: varchar(255) + default: null + notNull: true +primaryKey: + - category_id diff --git a/e2e-tests/data/my-guitar-shop/customers.jsonl b/e2e-tests/data/my-guitar-shop/customers.jsonl new file mode 100644 index 000000000..679bb3506 --- /dev/null +++ b/e2e-tests/data/my-guitar-shop/customers.jsonl @@ -0,0 +1,9 @@ +{"__isStreamHeader":true,"pureName":"customers","tableRowCount":"8","tableEngine":"InnoDB","objectComment":"","modifyDate":"2025-02-03 02:56:32","objectId":"customers","contentHash":"2025-02-03 02:56:32","columns":[{"notNull":true,"autoIncrement":true,"columnName":"customer_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"email_address","columnComment":"","dataType":"varchar(255)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"password","columnComment":"","dataType":"varchar(60)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"first_name","columnComment":"","dataType":"varchar(60)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"last_name","columnComment":"","dataType":"varchar(60)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":false,"autoIncrement":false,"columnName":"shipping_address_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":false,"autoIncrement":false,"columnName":"billing_address_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false}],"primaryKey":{"constraintName":"PRIMARY","pureName":"customers","constraintType":"primaryKey","columns":[{"columnName":"customer_id"}]},"foreignKeys":[],"indexes":[],"uniques":[{"constraintName":"email_address","columns":[{"columnName":"email_address"}]}],"engine":"mysql@dbgate-plugin-mysql"} +{"customer_id":1,"email_address":"allan.sherwood@yahoo.com","password":"650215acec746f0e32bdfff387439eefc1358737","first_name":"Allan","last_name":"Sherwood","shipping_address_id":1,"billing_address_id":2} +{"customer_id":2,"email_address":"barryz@gmail.com","password":"3f563468d42a448cb1e56924529f6e7bbe529cc7","first_name":"Barry","last_name":"Zimmer","shipping_address_id":3,"billing_address_id":3} +{"customer_id":3,"email_address":"christineb@solarone.com","password":"ed19f5c0833094026a2f1e9e6f08a35d26037066","first_name":"Christine","last_name":"Brown","shipping_address_id":4,"billing_address_id":4} +{"customer_id":4,"email_address":"david.goldstein@hotmail.com","password":"b444ac06613fc8d63795be9ad0beaf55011936ac","first_name":"David","last_name":"Goldstein","shipping_address_id":5,"billing_address_id":6} +{"customer_id":5,"email_address":"erinv@gmail.com","password":"109f4b3c50d7b0df729d299bc6f8e9ef9066971f","first_name":"Erin","last_name":"Valentino","shipping_address_id":7,"billing_address_id":7} +{"customer_id":6,"email_address":"frankwilson@sbcglobal.net","password":"3ebfa301dc59196f18593c45e519287a23297589","first_name":"Frank Lee","last_name":"Wilson","shipping_address_id":8,"billing_address_id":8} +{"customer_id":7,"email_address":"gary_hernandez@yahoo.com","password":"1ff2b3704aede04eecb51e50ca698efd50a1379b","first_name":"Gary","last_name":"Hernandez","shipping_address_id":9,"billing_address_id":10} +{"customer_id":8,"email_address":"heatheresway@mac.com","password":"911ddc3b8f9a13b5499b6bc4638a2b4f3f68bf23","first_name":"Heather","last_name":"Esway","shipping_address_id":11,"billing_address_id":12} diff --git a/e2e-tests/data/my-guitar-shop/customers.table.yaml b/e2e-tests/data/my-guitar-shop/customers.table.yaml new file mode 100644 index 000000000..8b9c8d8ac --- /dev/null +++ b/e2e-tests/data/my-guitar-shop/customers.table.yaml @@ -0,0 +1,31 @@ +name: customers +columns: + - name: customer_id + type: int + default: null + autoIncrement: true + notNull: true + - name: email_address + type: varchar(255) + default: null + notNull: true + - name: password + type: varchar(60) + default: null + notNull: true + - name: first_name + type: varchar(60) + default: null + notNull: true + - name: last_name + type: varchar(60) + default: null + notNull: true + - name: shipping_address_id + type: int + default: null + - name: billing_address_id + type: int + default: null +primaryKey: + - customer_id diff --git a/e2e-tests/data/my-guitar-shop/order_items.jsonl b/e2e-tests/data/my-guitar-shop/order_items.jsonl new file mode 100644 index 000000000..7813b6d05 --- /dev/null +++ b/e2e-tests/data/my-guitar-shop/order_items.jsonl @@ -0,0 +1,13 @@ +{"__isStreamHeader":true,"pureName":"order_items","tableRowCount":"12","tableEngine":"InnoDB","objectComment":"","modifyDate":"2025-02-03 02:56:33","objectId":"order_items","contentHash":"2025-02-03 02:56:33","columns":[{"notNull":true,"autoIncrement":true,"columnName":"item_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"order_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"product_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"item_price","columnComment":"","dataType":"decimal(10,2)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"discount_amount","columnComment":"","dataType":"decimal(10,2)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"quantity","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false}],"primaryKey":{"constraintName":"PRIMARY","pureName":"order_items","constraintType":"primaryKey","columns":[{"columnName":"item_id"}]},"foreignKeys":[{"constraintName":"items_fk_products","constraintType":"foreignKey","pureName":"order_items","refTableName":"products","updateAction":"NO ACTION","deleteAction":"NO ACTION","columns":[{"columnName":"product_id","refColumnName":"product_id"}]},{"constraintName":"items_fk_orders","constraintType":"foreignKey","pureName":"order_items","refTableName":"orders","updateAction":"NO ACTION","deleteAction":"NO ACTION","columns":[{"columnName":"order_id","refColumnName":"order_id"}]}],"indexes":[{"constraintName":"items_fk_orders","indexType":"BTREE","isUnique":false,"columns":[{"columnName":"order_id","isDescending":0}]},{"constraintName":"items_fk_products","indexType":"BTREE","isUnique":false,"columns":[{"columnName":"product_id","isDescending":0}]}],"uniques":[],"engine":"mysql@dbgate-plugin-mysql"} +{"item_id":1,"order_id":1,"product_id":2,"item_price":"1199.00","discount_amount":"359.70","quantity":1} +{"item_id":2,"order_id":2,"product_id":4,"item_price":"489.99","discount_amount":"186.20","quantity":1} +{"item_id":3,"order_id":3,"product_id":3,"item_price":"2517.00","discount_amount":"1308.84","quantity":1} +{"item_id":4,"order_id":3,"product_id":6,"item_price":"415.00","discount_amount":"161.85","quantity":1} +{"item_id":5,"order_id":4,"product_id":2,"item_price":"1199.00","discount_amount":"359.70","quantity":2} +{"item_id":6,"order_id":5,"product_id":5,"item_price":"299.00","discount_amount":"0.00","quantity":1} +{"item_id":7,"order_id":6,"product_id":5,"item_price":"299.00","discount_amount":"0.00","quantity":1} +{"item_id":8,"order_id":7,"product_id":1,"item_price":"699.00","discount_amount":"209.70","quantity":1} +{"item_id":9,"order_id":7,"product_id":7,"item_price":"799.99","discount_amount":"240.00","quantity":1} +{"item_id":10,"order_id":7,"product_id":9,"item_price":"699.99","discount_amount":"210.00","quantity":1} +{"item_id":11,"order_id":8,"product_id":10,"item_price":"799.99","discount_amount":"120.00","quantity":1} +{"item_id":12,"order_id":9,"product_id":1,"item_price":"699.00","discount_amount":"209.70","quantity":1} diff --git a/e2e-tests/data/my-guitar-shop/order_items.table.yaml b/e2e-tests/data/my-guitar-shop/order_items.table.yaml new file mode 100644 index 000000000..77bfc190e --- /dev/null +++ b/e2e-tests/data/my-guitar-shop/order_items.table.yaml @@ -0,0 +1,40 @@ +name: order_items +columns: + - name: item_id + type: int + default: null + autoIncrement: true + notNull: true + - name: order_id + type: int + default: null + notNull: true + references: orders + - name: product_id + type: int + default: null + notNull: true + references: products + - name: item_price + type: decimal(10,2) + default: null + notNull: true + - name: discount_amount + type: decimal(10,2) + default: null + notNull: true + - name: quantity + type: int + default: null + notNull: true +primaryKey: + - item_id +indexes: + - name: items_fk_orders + unique: false + columns: + - order_id + - name: items_fk_products + unique: false + columns: + - product_id diff --git a/e2e-tests/data/my-guitar-shop/orders.jsonl b/e2e-tests/data/my-guitar-shop/orders.jsonl new file mode 100644 index 000000000..fd5b56830 --- /dev/null +++ b/e2e-tests/data/my-guitar-shop/orders.jsonl @@ -0,0 +1,10 @@ +{"__isStreamHeader":true,"pureName":"orders","tableRowCount":"9","tableEngine":"InnoDB","objectComment":"","modifyDate":"2025-02-03 02:56:32","objectId":"orders","contentHash":"2025-02-03 02:56:32","columns":[{"notNull":true,"autoIncrement":true,"columnName":"order_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"customer_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"order_date","columnComment":"","dataType":"datetime","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"ship_amount","columnComment":"","dataType":"decimal(10,2)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"tax_amount","columnComment":"","dataType":"decimal(10,2)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":false,"autoIncrement":false,"columnName":"ship_date","columnComment":"","dataType":"datetime","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"ship_address_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"card_type","columnComment":"","dataType":"varchar(50)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"card_number","columnComment":"","dataType":"char(16)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"card_expires","columnComment":"","dataType":"char(7)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"billing_address_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false}],"primaryKey":{"constraintName":"PRIMARY","pureName":"orders","constraintType":"primaryKey","columns":[{"columnName":"order_id"}]},"foreignKeys":[{"constraintName":"orders_fk_customers","constraintType":"foreignKey","pureName":"orders","refTableName":"customers","updateAction":"NO ACTION","deleteAction":"NO ACTION","columns":[{"columnName":"customer_id","refColumnName":"customer_id"}]}],"indexes":[{"constraintName":"orders_fk_customers","indexType":"BTREE","isUnique":false,"columns":[{"columnName":"customer_id","isDescending":0}]}],"uniques":[],"engine":"mysql@dbgate-plugin-mysql"} +{"order_id":1,"customer_id":1,"order_date":"2018-03-28 09:40:28","ship_amount":"5.00","tax_amount":"32.32","ship_date":"2018-03-30 15:32:51","ship_address_id":1,"card_type":"Visa","card_number":"4111111111111111","card_expires":"04/2020","billing_address_id":2} +{"order_id":2,"customer_id":2,"order_date":"2018-03-28 11:23:20","ship_amount":"5.00","tax_amount":"0.00","ship_date":"2018-03-29 12:52:14","ship_address_id":3,"card_type":"Visa","card_number":"4012888888881881","card_expires":"08/2019","billing_address_id":3} +{"order_id":3,"customer_id":1,"order_date":"2018-03-29 09:44:58","ship_amount":"10.00","tax_amount":"89.92","ship_date":"2018-03-31 09:11:41","ship_address_id":1,"card_type":"Visa","card_number":"4111111111111111","card_expires":"04/2017","billing_address_id":2} +{"order_id":4,"customer_id":3,"order_date":"2018-03-30 15:22:31","ship_amount":"5.00","tax_amount":"0.00","ship_date":"2018-04-03 16:32:21","ship_address_id":4,"card_type":"American Express","card_number":"378282246310005","card_expires":"04/2016","billing_address_id":4} +{"order_id":5,"customer_id":4,"order_date":"2018-03-31 05:43:11","ship_amount":"5.00","tax_amount":"0.00","ship_date":"2018-04-02 14:21:12","ship_address_id":5,"card_type":"Visa","card_number":"4111111111111111","card_expires":"04/2019","billing_address_id":6} +{"order_id":6,"customer_id":5,"order_date":"2018-03-31 18:37:22","ship_amount":"5.00","tax_amount":"0.00","ship_date":null,"ship_address_id":7,"card_type":"Discover","card_number":"6011111111111117","card_expires":"04/2019","billing_address_id":7} +{"order_id":7,"customer_id":6,"order_date":"2018-04-01 23:11:12","ship_amount":"15.00","tax_amount":"0.00","ship_date":"2018-04-03 10:21:35","ship_address_id":8,"card_type":"MasterCard","card_number":"5555555555554444","card_expires":"04/2019","billing_address_id":8} +{"order_id":8,"customer_id":7,"order_date":"2018-04-02 11:26:38","ship_amount":"5.00","tax_amount":"0.00","ship_date":null,"ship_address_id":9,"card_type":"Visa","card_number":"4012888888881881","card_expires":"04/2019","billing_address_id":10} +{"order_id":9,"customer_id":4,"order_date":"2018-04-03 12:22:31","ship_amount":"5.00","tax_amount":"0.00","ship_date":null,"ship_address_id":5,"card_type":"Visa","card_number":"4111111111111111","card_expires":"04/2019","billing_address_id":6} diff --git a/e2e-tests/data/my-guitar-shop/orders.table.yaml b/e2e-tests/data/my-guitar-shop/orders.table.yaml new file mode 100644 index 000000000..e71759cb7 --- /dev/null +++ b/e2e-tests/data/my-guitar-shop/orders.table.yaml @@ -0,0 +1,54 @@ +name: orders +columns: + - name: order_id + type: int + default: null + autoIncrement: true + notNull: true + - name: customer_id + type: int + default: null + notNull: true + references: customers + - name: order_date + type: datetime + default: null + notNull: true + - name: ship_amount + type: decimal(10,2) + default: null + notNull: true + - name: tax_amount + type: decimal(10,2) + default: null + notNull: true + - name: ship_date + type: datetime + default: null + - name: ship_address_id + type: int + default: null + notNull: true + - name: card_type + type: varchar(50) + default: null + notNull: true + - name: card_number + type: char(16) + default: null + notNull: true + - name: card_expires + type: char(7) + default: null + notNull: true + - name: billing_address_id + type: int + default: null + notNull: true +primaryKey: + - order_id +indexes: + - name: orders_fk_customers + unique: false + columns: + - customer_id diff --git a/e2e-tests/data/my-guitar-shop/products.jsonl b/e2e-tests/data/my-guitar-shop/products.jsonl new file mode 100644 index 000000000..d4248de8a --- /dev/null +++ b/e2e-tests/data/my-guitar-shop/products.jsonl @@ -0,0 +1,11 @@ +{"__isStreamHeader":true,"pureName":"products","tableRowCount":"10","tableEngine":"InnoDB","objectComment":"","modifyDate":"2025-02-03 02:56:32","objectId":"products","contentHash":"2025-02-03 02:56:32","columns":[{"notNull":true,"autoIncrement":true,"columnName":"product_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"category_id","columnComment":"","dataType":"int","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"product_code","columnComment":"","dataType":"varchar(10)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"product_name","columnComment":"","dataType":"varchar(255)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"description","columnComment":"","dataType":"text","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"list_price","columnComment":"","dataType":"decimal(10,2)","defaultValue":null,"isUnsigned":false,"isZerofill":false},{"notNull":true,"autoIncrement":false,"columnName":"discount_percent","columnComment":"","dataType":"decimal(10,2)","defaultValue":"0.00","isUnsigned":false,"isZerofill":false},{"notNull":false,"autoIncrement":false,"columnName":"date_added","columnComment":"","dataType":"datetime","defaultValue":null,"isUnsigned":false,"isZerofill":false}],"primaryKey":{"constraintName":"PRIMARY","pureName":"products","constraintType":"primaryKey","columns":[{"columnName":"product_id"}]},"foreignKeys":[{"constraintName":"products_fk_categories","constraintType":"foreignKey","pureName":"products","refTableName":"categories","updateAction":"NO ACTION","deleteAction":"NO ACTION","columns":[{"columnName":"category_id","refColumnName":"category_id"}]}],"indexes":[{"constraintName":"products_fk_categories","indexType":"BTREE","isUnique":false,"columns":[{"columnName":"category_id","isDescending":0}]}],"uniques":[{"constraintName":"product_code","columns":[{"columnName":"product_code"}]}],"engine":"mysql@dbgate-plugin-mysql"} +{"product_id":1,"category_id":1,"product_code":"strat","product_name":"Fender Stratocaster","description":"The Fender Stratocaster is the electric guitar design that changed the world. New features include a tinted neck, parchment pickguard and control knobs, and a '70s-style logo. Includes select alder body, 21-fret maple neck with your choice of a rosewood or maple fretboard, 3 single-coil pickups, vintage-style tremolo, and die-cast tuning keys. This guitar features a thicker bridge block for increased sustain and a more stable point of contact with the strings. At this low price, why play anything but the real thing?\r\n\r\nFeatures:\r\n\r\n* New features:\r\n* Thicker bridge block\r\n* 3-ply parchment pick guard\r\n* Tinted neck","list_price":"699.00","discount_percent":"30.00","date_added":"2017-10-30 09:32:40"} +{"product_id":2,"category_id":1,"product_code":"les_paul","product_name":"Gibson Les Paul","description":"This Les Paul guitar offers a carved top and humbucking pickups. It has a simple yet elegant design. Cutting-yet-rich tone?the hallmark of the Les Paul?pours out of the 490R and 498T Alnico II magnet humbucker pickups, which are mounted on a carved maple top with a mahogany back. The faded finish models are equipped with BurstBucker Pro pickups and a mahogany top. This guitar includes a Gibson hardshell case (Faded and satin finish models come with a gig bag) and a limited lifetime warranty.\r\n\r\nFeatures:\r\n\r\n* Carved maple top and mahogany back (Mahogany top on faded finish models)\r\n* Mahogany neck, '59 Rounded Les Paul\r\n* Rosewood fingerboard (Ebony on Alpine white)\r\n* Tune-O-Matic bridge with stopbar\r\n* Chrome or gold hardware\r\n* 490R and 498T Alnico 2 magnet humbucker pickups (BurstBucker Pro on faded finish models)\r\n* 2 volume and 2 tone knobs, 3-way switch","list_price":"1199.00","discount_percent":"30.00","date_added":"2017-12-05 16:33:13"} +{"product_id":3,"category_id":1,"product_code":"sg","product_name":"Gibson SG","description":"This Gibson SG electric guitar takes the best of the '62 original and adds the longer and sturdier neck joint of the late '60s models. All the classic features you'd expect from a historic guitar. Hot humbuckers go from rich, sweet lightning to warm, tingling waves of sustain. A silky-fast rosewood fretboard plays like a dream. The original-style beveled mahogany body looks like a million bucks. Plus, Tune-O-Matic bridge and chrome hardware. Limited lifetime warranty. Includes hardshell case.\r\n\r\nFeatures:\r\n\r\n* Double-cutaway beveled mahogany body\r\n* Set mahogany neck with rounded '50s profile\r\n* Bound rosewood fingerboard with trapezoid inlays\r\n* Tune-O-Matic bridge with stopbar tailpiece\r\n* Chrome hardware\r\n* 490R humbucker in the neck position\r\n* 498T humbucker in the bridge position\r\n* 2 volume knobs, 2 tone knobs, 3-way switch\r\n* 24-3/4\" scale","list_price":"2517.00","discount_percent":"52.00","date_added":"2018-02-04 11:04:31"} +{"product_id":4,"category_id":1,"product_code":"fg700s","product_name":"Yamaha FG700S","description":"The Yamaha FG700S solid top acoustic guitar has the ultimate combo for projection and pure tone. The expertly braced spruce top speaks clearly atop the rosewood body. It has a rosewood fingerboard, rosewood bridge, die-cast tuners, body and neck binding, and a tortoise pickguard.\r\n\r\nFeatures:\r\n\r\n* Solid Sitka spruce top\r\n* Rosewood back and sides\r\n* Rosewood fingerboard\r\n* Rosewood bridge\r\n* White/black body and neck binding\r\n* Die-cast tuners\r\n* Tortoise pickguard\r\n* Limited lifetime warranty","list_price":"489.99","discount_percent":"38.00","date_added":"2018-06-01 11:12:59"} +{"product_id":5,"category_id":1,"product_code":"washburn","product_name":"Washburn D10S","description":"The Washburn D10S acoustic guitar is superbly crafted with a solid spruce top and mahogany back and sides for exceptional tone. A mahogany neck and rosewood fingerboard make fretwork a breeze, while chrome Grover-style machines keep you perfectly tuned. The Washburn D10S comes with a limited lifetime warranty.\r\n\r\nFeatures:\r\n\r\n * Spruce top\r\n * Mahogany back, sides\r\n * Mahogany neck Rosewood fingerboard\r\n * Chrome Grover-style machines","list_price":"299.00","discount_percent":"0.00","date_added":"2018-07-30 13:58:35"} +{"product_id":6,"category_id":1,"product_code":"rodriguez","product_name":"Rodriguez Caballero 11","description":"Featuring a carefully chosen, solid Canadian cedar top and laminated bubinga back and sides, the Caballero 11 classical guitar is a beauty to behold and play. The headstock and fretboard are of Indian rosewood. Nickel-plated tuners and Silver-plated frets are installed to last a lifetime. The body binding and wood rosette are exquisite.\r\n\r\nThe Rodriguez Guitar is hand crafted and glued to create precise balances. From the invisible careful sanding, even inside the body, that ensures the finished instrument's purity of tone, to the beautifully unique rosette inlays around the soundhole and on the back of the neck, each guitar is a credit to its luthier and worthy of being handed down from one generation to another.\r\n\r\nThe tone, resonance and beauty of fine guitars are all dependent upon the wood from which they are made. The wood used in the construction of Rodriguez guitars is carefully chosen and aged to guarantee the highest quality. No wood is purchased before the tree has been cut down, and at least 2 years must elapse before the tree is turned into lumber. The wood has to be well cut from the log. The grain must be close and absolutely vertical. The shop is totally free from humidity.","list_price":"415.00","discount_percent":"39.00","date_added":"2018-07-30 14:12:41"} +{"product_id":7,"category_id":2,"product_code":"precision","product_name":"Fender Precision","description":"The Fender Precision bass guitar delivers the sound, look, and feel today's bass players demand. This bass features that classic P-Bass old-school design. Each Precision bass boasts contemporary features and refinements that make it an excellent value. Featuring an alder body and a split single-coil pickup, this classic electric bass guitar lives up to its Fender legacy.\r\n\r\nFeatures:\r\n\r\n* Body: Alder\r\n* Neck: Maple, modern C shape, tinted satin urethane finish\r\n* Fingerboard: Rosewood or maple (depending on color)\r\n* 9-1/2\" Radius (241 mm)\r\n* Frets: 20 Medium-jumbo frets\r\n* Pickups: 1 Standard Precision Bass split single-coil pickup (Mid)\r\n* Controls: Volume, Tone\r\n* Bridge: Standard vintage style with single groove saddles\r\n* Machine heads: Standard\r\n* Hardware: Chrome\r\n* Pickguard: 3-Ply Parchment\r\n* Scale Length: 34\" (864 mm)\r\n* Width at Nut: 1-5/8\" (41.3 mm)\r\n* Unique features: Knurled chrome P Bass knobs, Fender transition logo","list_price":"799.99","discount_percent":"30.00","date_added":"2018-06-01 11:29:35"} +{"product_id":8,"category_id":2,"product_code":"hofner","product_name":"Hofner Icon","description":"With authentic details inspired by the original, the Hofner Icon makes the legendary violin bass available to the rest of us. Don't get the idea that this a just a \"nowhere man\" look-alike. This quality instrument features a real spruce top and beautiful flamed maple back and sides. The semi-hollow body and set neck will give you the warm, round tone you expect from the violin bass.\r\n\r\nFeatures:\r\n\r\n* Authentic details inspired by the original\r\n* Spruce top\r\n* Flamed maple back and sides\r\n* Set neck\r\n* Rosewood fretboard\r\n* 30\" scale\r\n* 22 frets\r\n* Dot inlay","list_price":"499.99","discount_percent":"25.00","date_added":"2018-07-30 14:18:33"} +{"product_id":9,"category_id":3,"product_code":"ludwig","product_name":"Ludwig 5-piece Drum Set with Cymbals","description":"This product includes a Ludwig 5-piece drum set and a Zildjian starter cymbal pack.\r\n\r\nWith the Ludwig drum set, you get famous Ludwig quality. This set features a bass drum, two toms, a floor tom, and a snare?each with a wrapped finish. Drum hardware includes LA214FP bass pedal, snare stand, cymbal stand, hi-hat stand, and a throne.\r\n\r\nWith the Zildjian cymbal pack, you get a 14\" crash, 18\" crash/ride, and a pair of 13\" hi-hats. Sound grooves and round hammer strikes in a simple circular pattern on the top surface of these cymbals magnify the basic sound of the distinctive alloy.\r\n\r\nFeatures:\r\n\r\n* Famous Ludwig quality\r\n* Wrapped finishes\r\n* 22\" x 16\" kick drum\r\n* 12\" x 10\" and 13\" x 11\" toms\r\n* 16\" x 16\" floor tom\r\n* 14\" x 6-1/2\" snare drum kick pedal\r\n* Snare stand\r\n* Straight cymbal stand hi-hat stand\r\n* FREE throne","list_price":"699.99","discount_percent":"30.00","date_added":"2018-07-30 12:46:40"} +{"product_id":10,"category_id":3,"product_code":"tama","product_name":"Tama 5-Piece Drum Set with Cymbals","description":"The Tama 5-piece Drum Set is the most affordable Tama drum kit ever to incorporate so many high-end features.\r\n\r\nWith over 40 years of experience, Tama knows what drummers really want. Which is why, no matter how long you've been playing the drums, no matter what budget you have to work with, Tama has the set you need, want, and can afford. Every aspect of the modern drum kit was exhaustively examined and reexamined and then improved before it was accepted as part of the Tama design. Which is why, if you start playing Tama now as a beginner, you'll still enjoy playing it when you've achieved pro-status. That's how good these groundbreaking new drums are.\r\n\r\nOnly Tama comes with a complete set of genuine Meinl HCS cymbals. These high-quality brass cymbals are made in Germany and are sonically matched so they sound great together. They are even lathed for a more refined tonal character. The set includes 14\" hi-hats, 16\" crash cymbal, and a 20\" ride cymbal.\r\n\r\nFeatures:\r\n\r\n* 100% poplar 6-ply/7.5mm shells\r\n* Precise bearing edges\r\n* 100% glued finishes\r\n* Original small lugs\r\n* Drum heads\r\n* Accu-tune bass drum hoops\r\n* Spur brackets\r\n* Tom holder\r\n* Tom brackets","list_price":"799.99","discount_percent":"15.00","date_added":"2018-07-30 13:14:15"} diff --git a/e2e-tests/data/my-guitar-shop/products.table.yaml b/e2e-tests/data/my-guitar-shop/products.table.yaml new file mode 100644 index 000000000..fb00a8d5a --- /dev/null +++ b/e2e-tests/data/my-guitar-shop/products.table.yaml @@ -0,0 +1,42 @@ +name: products +columns: + - name: product_id + type: int + default: null + autoIncrement: true + notNull: true + - name: category_id + type: int + default: null + notNull: true + references: categories + - name: product_code + type: varchar(10) + default: null + notNull: true + - name: product_name + type: varchar(255) + default: null + notNull: true + - name: description + type: text + default: null + notNull: true + - name: list_price + type: decimal(10,2) + default: null + notNull: true + - name: discount_percent + type: decimal(10,2) + default: '0.00' + notNull: true + - name: date_added + type: datetime + default: null +primaryKey: + - product_id +indexes: + - name: products_fk_categories + unique: false + columns: + - category_id diff --git a/e2e-tests/env/multi-sql/.env b/e2e-tests/env/multi-sql/.env new file mode 100644 index 000000000..2954399d6 --- /dev/null +++ b/e2e-tests/env/multi-sql/.env @@ -0,0 +1,17 @@ +CONNECTIONS=mysql,postgres + +LABEL_mysql=MySql-connection +SERVER_mysql=localhost +USER_mysql=root +PASSWORD_mysql=Pwd2020Db +PORT_mysql=16004 +ENGINE_mysql=mysql@dbgate-plugin-mysql +DBCONFIG_mysql=[{"name":"MyChinook","connectionColor":"cyan"}] + +LABEL_postgres=Postgres-connection +SERVER_postgres=localhost +USER_postgres=postgres +PASSWORD_postgres=Pwd2020Db +PORT_postgres=16000 +ENGINE_postgres=postgres@dbgate-plugin-postgres +DBCONFIG_postgres=[{"name":"PgChinook","connectionColor":"red"}] diff --git a/e2e-tests/init/multi-sql.js b/e2e-tests/init/multi-sql.js new file mode 100644 index 000000000..0b41f64cc --- /dev/null +++ b/e2e-tests/init/multi-sql.js @@ -0,0 +1,56 @@ +const path = require('path'); + +const dbgateApi = require('dbgate-api'); +dbgateApi.initializeApiEnvironment(); +const dbgatePluginMysql = require('dbgate-plugin-mysql'); +dbgateApi.registerPlugins(dbgatePluginMysql); +const dbgatePluginPostgres = require('dbgate-plugin-postgres'); +dbgateApi.registerPlugins(dbgatePluginPostgres); + +async function createDb(connection, dropDbSql, createDbSql) { + await dbgateApi.executeQuery({ + connection, + sql: dropDbSql, + }); + + await dbgateApi.executeQuery({ + connection, + sql: createDbSql, + }); + + await dbgateApi.importDbFromFolder({ + connection: { + ...connection, + database: 'my_quitar_shop', + }, + folder: path.resolve(path.join(__dirname, '../data/my-guitar-shop')), + }); +} + +async function run() { + await createDb( + { + server: process.env.SERVER_postgres, + user: process.env.USER_postgres, + password: process.env.PASSWORD_postgres, + port: process.env.PORT_postgres, + engine: 'postgres@dbgate-plugin-postgres', + }, + 'drop database if exists my_quitar_shop', + 'create database my_quitar_shop' + ); + + await createDb( + { + server: process.env.SERVER_mysql, + user: process.env.USER_mysql, + password: process.env.PASSWORD_mysql, + port: process.env.PORT_mysql, + engine: 'mysql@dbgate-plugin-mysql', + }, + 'drop database if exists my_quitar_shop', + 'create database my_quitar_shop' + ); +} + +dbgateApi.runScript(run); diff --git a/e2e-tests/package.json b/e2e-tests/package.json index 7500464dc..619c37819 100644 --- a/e2e-tests/package.json +++ b/e2e-tests/package.json @@ -20,20 +20,23 @@ "cy:run:oauth": "cypress run --spec cypress/e2e/oauth.cy.js", "cy:run:browse-data": "cypress run --spec cypress/e2e/browse-data.cy.js", "cy:run:team": "cypress run --spec cypress/e2e/team.cy.js", + "cy:run:multi-sql": "cypress run --spec cypress/e2e/multi-sql.cy.js", "start:add-connection": "cd .. && node packer/build/bundle.js --listen-api --run-e2e-tests", "start:portal": "cd .. && env-cmd -f e2e-tests/env/portal/.env node e2e-tests/init/portal.js && env-cmd -f e2e-tests/env/portal/.env node packer/build/bundle.js --listen-api --run-e2e-tests", "start:oauth": "cd .. && env-cmd -f e2e-tests/env/oauth/.env node packer/build/bundle.js --listen-api --run-e2e-tests", "start:browse-data": "cd .. && env-cmd -f e2e-tests/env/browse-data/.env node e2e-tests/init/browse-data.js && env-cmd -f e2e-tests/env/browse-data/.env node packer/build/bundle.js --listen-api --run-e2e-tests", "start:team": "cd .. && env-cmd -f e2e-tests/env/team/.env node e2e-tests/init/team.js && env-cmd -f e2e-tests/env/team/.env node packer/build/bundle.js --listen-api --run-e2e-tests", + "start:multi-sql": "cd .. && env-cmd -f e2e-tests/env/multi-sql/.env node e2e-tests/init/multi-sql.js && env-cmd -f e2e-tests/env/multi-sql/.env node packer/build/bundle.js --listen-api --run-e2e-tests", "test:add-connection": "start-server-and-test start:add-connection http://localhost:3000 cy:run:add-connection", "test:portal": "start-server-and-test start:portal http://localhost:3000 cy:run:portal", "test:oauth": "start-server-and-test start:oauth http://localhost:3000 cy:run:oauth", "test:browse-data": "start-server-and-test start:browse-data http://localhost:3000 cy:run:browse-data", "test:team": "start-server-and-test start:team http://localhost:3000 cy:run:team", + "test:multi-sql": "start-server-and-test start:multi-sql http://localhost:3000 cy:run:multi-sql", - "test": "yarn test:add-connection && yarn test:portal && yarn test:oauth && yarn test:browse-data && yarn test:team", + "test": "yarn test:add-connection && yarn test:portal && yarn test:oauth && yarn test:browse-data && yarn test:team && yaran test:multi-sql", "test:ci": "yarn test" }, "dependencies": {} diff --git a/packages/api/src/shell/importDbFromFolder.js b/packages/api/src/shell/importDbFromFolder.js new file mode 100644 index 000000000..8eec0d174 --- /dev/null +++ b/packages/api/src/shell/importDbFromFolder.js @@ -0,0 +1,82 @@ +const path = require('path'); +const fs = require('fs-extra'); +const executeQuery = require('./executeQuery'); +const { connectUtility } = require('../utility/connectUtility'); +const requireEngineDriver = require('../utility/requireEngineDriver'); +const { getAlterDatabaseScript, DatabaseAnalyser } = require('dbgate-tools'); +const importDbModel = require('../utility/importDbModel'); +const jsonLinesReader = require('./jsonLinesReader'); +const tableWriter = require('./tableWriter'); +const copyStream = require('./copyStream'); + +/** + * Deploys database model stored in modelFolder (table as yamls) to database + * @param {object} options + * @param {connectionType} options.connection - connection object + * @param {object} options.systemConnection - system connection (result of driver.connect). If not provided, new connection will be created + * @param {object} options.driver - driver object. If not provided, it will be loaded from connection + * @param {string} options.folder - folder with model files (YAML files for tables, SQL files for views, procedures, ...) + * @param {function[]} options.modelTransforms - array of functions for transforming model + */ +async function importDbFromFolder({ connection, systemConnection, driver, folder, modelTransforms }) { + if (!driver) driver = requireEngineDriver(connection); + const dbhan = systemConnection || (await connectUtility(driver, connection, 'read')); + + try { + const model = await importDbModel(folder); + + let modelAdapted = { + ...model, + tables: model.tables.map(table => driver.adaptTableInfo(table)), + }; + for (const transform of modelTransforms || []) { + modelAdapted = transform(modelAdapted); + } + + const modelNoFk = { + ...modelAdapted, + tables: modelAdapted.tables.map(table => ({ + ...table, + foreignKeys: [], + })), + }; + + const { sql } = getAlterDatabaseScript( + DatabaseAnalyser.createEmptyStructure(), + modelNoFk, + {}, + DatabaseAnalyser.createEmptyStructure(), + modelNoFk, + driver + ); + // console.log('CREATING STRUCTURE:', sql); + await executeQuery({ connection, systemConnection: dbhan, driver, sql, logScriptItems: true }); + + for (const table of model.tables) { + const fileName = path.join(folder, `${table.pureName}.jsonl`); + if (await fs.exists(fileName)) { + const src = await jsonLinesReader({ fileName }); + const dst = await tableWriter({ + connection, + pureName: table.pureName, + }); + await copyStream(src, dst); + } + } + + const dmp = driver.createDumper(); + for (const table of modelAdapted.tables) { + for (const fk of table.foreignKeys) { + dmp.createForeignKey(fk); + } + } + // create foreign keys + await executeQuery({ connection, systemConnection: dbhan, driver, sql: dmp.s, logScriptItems: true }); + } finally { + if (!systemConnection) { + await driver.close(dbhan); + } + } +} + +module.exports = importDbFromFolder; diff --git a/packages/api/src/shell/index.js b/packages/api/src/shell/index.js index 54b9da1aa..1648301d7 100644 --- a/packages/api/src/shell/index.js +++ b/packages/api/src/shell/index.js @@ -35,6 +35,7 @@ const sqlTextReplacementTransform = require('./sqlTextReplacementTransform'); const autoIndexForeignKeysTransform = require('./autoIndexForeignKeysTransform'); const generateDeploySql = require('./generateDeploySql'); const dropAllDbObjects = require('./dropAllDbObjects'); +const importDbFromFolder = require('./importDbFromFolder'); const dbgateApi = { queryReader, @@ -73,6 +74,7 @@ const dbgateApi = { autoIndexForeignKeysTransform, generateDeploySql, dropAllDbObjects, + importDbFromFolder, }; requirePlugin.initializeDbgateApi(dbgateApi); diff --git a/packages/tools/src/driverBase.ts b/packages/tools/src/driverBase.ts index 7f1cbe6e2..86d6caf37 100644 --- a/packages/tools/src/driverBase.ts +++ b/packages/tools/src/driverBase.ts @@ -233,8 +233,18 @@ export const driverBase = { return defaultCreator(changeSet, dbinfo); }, + adaptDataType(dataType: string) { + return dataType; + }, + adaptTableInfo(table) { - return table; + return { + ...table, + columns: table.columns?.map(col => ({ + ...col, + dataType: this.adaptDataType(col.dataType), + })), + }; }, async listSchemas(pool) { diff --git a/packages/types/engines.d.ts b/packages/types/engines.d.ts index 81586d4c2..dae1f2878 100644 --- a/packages/types/engines.d.ts +++ b/packages/types/engines.d.ts @@ -257,6 +257,8 @@ export interface EngineDriver extends FilterBehaviourProvider { ): any[]; // adapts table info from different source (import, other database) to be suitable for this database adaptTableInfo(table: TableInfo): TableInfo; + // simple data type adapter + adaptDataType(dataType: string): string; listSchemas(dbhan: DatabaseHandle): SchemaInfo[]; analyserClass?: any; diff --git a/plugins/dbgate-plugin-cassandra/src/frontend/driver.js b/plugins/dbgate-plugin-cassandra/src/frontend/driver.js index d7c14d79c..587569add 100644 --- a/plugins/dbgate-plugin-cassandra/src/frontend/driver.js +++ b/plugins/dbgate-plugin-cassandra/src/frontend/driver.js @@ -92,11 +92,12 @@ const driver = { ? { ...mysqlSplitterOptions, ignoreComments: true, preventSingleLineSplit: true } : mysqlSplitterOptions, adaptTableInfo(table) { - if (!table.primaryKey && !table.sortingKey) { - const hasIdColumn = table.columns.some((x) => x.columnName == 'id'); + const baseAdapted = driverBase.adaptTableInfo(table); + if (!baseAdapted.primaryKey && !baseAdapted.sortingKey) { + const hasIdColumn = baseAdapted.columns.some((x) => x.columnName == 'id'); return { - ...table, + ...baseAdapted, primaryKey: { columns: [ { @@ -113,11 +114,11 @@ const driver = { }, ] : []), - ...table.columns, + ...baseAdapted.columns, ], }; } - return table; + return baseAdapted; }, }; diff --git a/plugins/dbgate-plugin-clickhouse/src/frontend/driver.js b/plugins/dbgate-plugin-clickhouse/src/frontend/driver.js index 380cb92d2..33a2a884c 100644 --- a/plugins/dbgate-plugin-clickhouse/src/frontend/driver.js +++ b/plugins/dbgate-plugin-clickhouse/src/frontend/driver.js @@ -192,13 +192,15 @@ const driver = { }, adaptTableInfo(table) { - if (!table.primaryKey && !table.sortingKey) { + const baseAdapted = driverBase.adaptTableInfo(table); + + if (!baseAdapted.primaryKey && !baseAdapted.sortingKey) { return { - ...table, + ...baseAdapted, tableEngine: 'Log', }; } - return table; + return baseAdapted; }, }; diff --git a/plugins/dbgate-plugin-postgres/src/frontend/drivers.js b/plugins/dbgate-plugin-postgres/src/frontend/drivers.js index 21f33683e..5ee498357 100644 --- a/plugins/dbgate-plugin-postgres/src/frontend/drivers.js +++ b/plugins/dbgate-plugin-postgres/src/frontend/drivers.js @@ -217,6 +217,11 @@ EXECUTE FUNCTION function_name();`, authTypeLabel: 'Connection mode', defaultAuthTypeName: 'hostPort', defaultSocketPath: '/var/run/postgresql', + + adaptDataType(dataType) { + if (dataType?.toLowerCase() == 'datetime') return 'timestamp'; + return dataType; + }, }; /** @type {import('dbgate-types').EngineDriver} */