Restante do código da função createTable 1/2
// Criação da tabela natural_person_clients
(await db).transaction(tx => {
tx.executeSql(
'CREATE TABLE IF NOT EXISTS natural_person_clients (' +
'id TEXT NOT NULL PRIMARY KEY,' +
'cpf CHAR(11) NOT NULL UNIQUE,' +
'rg CHAR(9) NULL UNIQUE,' +
'FOREIGN KEY (id) REFERENCES clients(id) ON DELETE NO ACTION ON UPDATE NO ACTION' +
');'
, [], () => console.log(`Tabela natural_person_clients criada com sucesso`), () => console.log(`Erro ao criar a tabela natural_person_clients`))
});
// Criação da tabela address_clients
(await db).transaction(tx => {
tx.executeSql(
'CREATE TABLE IF NOT EXISTS addresses_clients (' +
'id TEXT PRIMARY KEY NOT NULL UNIQUE,' +
'road VARCHAR(100) NOT NULL,' +
'number VARCHAR(10) NOT NULL,' +
'neighborhood VARCHAR(100) NOT NULL,' +
'complement VARCHAR(50) NULL,' +
'city VARCHAR(100) NOT NULL,' +
'state CHAR(2) NOT NULL,' +
'zip_code CHAR(8) NOT NULL,' +
'FOREIGN KEY (id) REFERENCES clients(id) ON DELETE NO ACTION ON UPDATE NO ACTION' +
');'
, [], () => console.log(`Tabela addresses_clients criada com sucesso`), () => console.log(`Erro ao criar a tabela addresses_clients`))
});
// Criação da tabela payment_methods
(await db).transaction(tx => {
tx.executeSql(
'CREATE TABLE IF NOT EXISTS payment_methods (' +
'id INTEGER NOT NULL PRIMARY KEY,' +
'name VARCHAR(45) NOT NULL UNIQUE,' +
'description VARCHAR(250) NULL,' +
'charge DECIMAL(10,2) NOT NULL DEFAULT 0,' +
'deadline INTEGER NOT NULL DEFAULT 1,' +
'maximum_installments INTEGER NOT NULL DEFAULT 1,' +
'active INTEGER NOT NULL DEFAULT 1,' +
'creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,' +
'modified_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,' +
'UNIQUE (name)' +
');'
, [], () => console.log(`Tabela payment_methods criada com sucesso`), () => console.log(`Erro ao criar a tabela payment_methods`))
});
// Criação da tabela orders
(await db).transaction(tx => {
tx.executeSql(
'CREATE TABLE IF NOT EXISTS orders (' +
'id TEXT NOT NULL PRIMARY KEY,' +
'id_server INT NULL,' +
'id_client TEXT NOT NULL,' +
'id_payment INT NOT NULL,' +
'id_seller INT NOT NULL,' +
'amount DECIMAL(20,2) NOT NULL,' +
'date DATETIME NOT NULL,' +
'status TEXT NOT NULL DEFAULT "waitingForSync" CHECK(status IN ("waitingForSync", "synced", "inSeparation", "waitingToBeSent", "sent", "delivered", "returned", "canceled", "concluded", "underObservation", "latePayment", "awaitingPayment")),' +
'active TINYINT(1) NOT NULL DEFAULT 1,' +
'creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,' +
'modified_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,' +
'UNIQUE (id_server),' +
'UNIQUE (id),' +
'FOREIGN KEY (id_client) REFERENCES clients(id) ON DELETE NO ACTION ON UPDATE NO ACTION,' +
'FOREIGN KEY (id_payment) REFERENCES payment_methods(id) ON DELETE NO ACTION ON UPDATE NO ACTION' +
');'
, [], () => console.log(`Tabela orders criada com sucesso`), () => console.log(`Erro ao criar a tabela orders`)
);
});
// Criação da tabela item_orders
(await db).transaction(tx => {
tx.executeSql(
'CREATE TABLE IF NOT EXISTS item_orders (' +
'id_order TEXT NOT NULL,' +
'id_product INT NOT NULL,' +
'amount DECIMAL(10,2) NOT NULL,' +
'unitary_value DECIMAL(20,2) NOT NULL,' +
'description VARCHAR(250) NULL,' +
'PRIMARY KEY (id_order, id_product),' +
'FOREIGN KEY (id_order) REFERENCES orders(id) ON DELETE NO ACTION ON UPDATE NO ACTION,' +
'FOREIGN KEY (id_product) REFERENCES products(id) ON DELETE NO ACTION ON UPDATE NO ACTION,' +
'INDEX id_product_idx (id_product ASC)' +
');'
, [], () => console.log('Tabela item_orders criada com sucesso'), () => console.log('Erro ao criar a tabela item_orders')
);
});