Browse Source

fix(test): Added sqlite sakila seeding sqlite file which will preserve the last updated time and removed the old one

pull/4278/head
Muhammed Mustafa 2 years ago
parent
commit
5aefc61e57
  1. 2
      packages/nocodb/src/lib/services/test/TestResetService/resetMetaSakilaSqliteProject.ts
  2. 265
      packages/nocodb/tests/sqlite-sakila-db/01-sqlite-sakila-schema.sql
  3. 92546
      packages/nocodb/tests/sqlite-sakila-db/02-sqlite-sakila-insert-data.sql
  4. 604
      packages/nocodb/tests/sqlite-sakila-db/03-sqlite-prefix-sakila-schema.sql
  5. 180
      packages/nocodb/tests/sqlite-sakila-db/03-sqlite-sakila-triggers.sql
  6. 231486
      packages/nocodb/tests/sqlite-sakila-db/04-sqlite-prefix-sakila-insert-data.sql
  7. BIN
      packages/nocodb/tests/sqlite-sakila-db/sakila.db
  8. BIN
      packages/nocodb/tests/sqlite-sakila-db/sakila_v2.db

2
packages/nocodb/src/lib/services/test/TestResetService/resetMetaSakilaSqliteProject.ts

@ -85,7 +85,7 @@ const seedSakilaSqliteFile = async (parallelId: string) => {
); );
await fs.copyFile( await fs.copyFile(
`${testsDir}/sqlite-sakila-db/sakila_v2.db`, `${testsDir}/sqlite-sakila-db/sakila.db`,
sqliteFilePath(parallelId) sqliteFilePath(parallelId)
); );
}; };

265
packages/nocodb/tests/sqlite-sakila-db/01-sqlite-sakila-schema.sql

@ -15,35 +15,16 @@ http://www.etl-tools.com
-- --
--DROP TABLE actor; --DROP TABLE actor;
select * from sqlite_master where type = 'trigger' and tbl_name='actor'
SELECT * FROM sqlite_master WHERE type = 'view'
CREATE TABLE actor ( CREATE TABLE actor (
actor_id numeric NOT NULL , actor_id INTEGER NOT NULL ,
first_name VARCHAR(45) NOT NULL, first_name VARCHAR(45) NOT NULL,
last_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL,
last_update TIMESTAMP NOT NULL, last_update TIMESTAMP,
PRIMARY KEY (actor_id) PRIMARY KEY (actor_id)
) ; )
CREATE INDEX idx_actor_last_name ON actor(last_name)
;
CREATE TRIGGER actor_trigger_ai AFTER INSERT ON actor
BEGIN
UPDATE actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
; ;
CREATE TRIGGER actor_trigger_au AFTER UPDATE ON actor CREATE INDEX idx_actor_last_name ON actor(last_name)
BEGIN
UPDATE actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
; ;
-- --
@ -51,34 +32,22 @@ CREATE TRIGGER actor_trigger_au AFTER UPDATE ON actor
-- --
CREATE TABLE country ( CREATE TABLE country (
country_id SMALLINT NOT NULL, country_id INTEGER NOT NULL,
country VARCHAR(50) NOT NULL, country VARCHAR(50) NOT NULL,
last_update TIMESTAMP, last_update TIMESTAMP,
PRIMARY KEY (country_id) PRIMARY KEY (country_id)
) )
; ;
CREATE TRIGGER country_trigger_ai AFTER INSERT ON country
BEGIN
UPDATE country SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER country_trigger_au AFTER UPDATE ON country
BEGIN
UPDATE country SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
-- --
-- Table structure for table city -- Table structure for table city
-- --
CREATE TABLE city ( CREATE TABLE city (
city_id int NOT NULL, city_id INTEGER NOT NULL,
city VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL,
country_id SMALLINT NOT NULL, country_id INTEGER NOT NULL,
last_update TIMESTAMP NOT NULL, last_update TIMESTAMP,
PRIMARY KEY (city_id), PRIMARY KEY (city_id),
CONSTRAINT fk_city_country FOREIGN KEY (country_id) REFERENCES country (country_id) ON DELETE NO ACTION ON UPDATE CASCADE CONSTRAINT fk_city_country FOREIGN KEY (country_id) REFERENCES country (country_id) ON DELETE NO ACTION ON UPDATE CASCADE
) )
@ -86,31 +55,19 @@ CREATE TABLE city (
CREATE INDEX idx_fk_country_id ON city(country_id) CREATE INDEX idx_fk_country_id ON city(country_id)
; ;
CREATE TRIGGER city_trigger_ai AFTER INSERT ON city
BEGIN
UPDATE city SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER city_trigger_au AFTER UPDATE ON city
BEGIN
UPDATE city SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
-- --
-- Table structure for table address -- Table structure for table address
-- --
CREATE TABLE address ( CREATE TABLE address (
address_id int NOT NULL, address_id INTEGER NOT NULL,
address VARCHAR(50) NOT NULL, address VARCHAR(50) NOT NULL,
address2 VARCHAR(50) DEFAULT NULL, address2 VARCHAR(50) DEFAULT NULL,
district VARCHAR(20) NOT NULL, district VARCHAR(20) NOT NULL,
city_id INT NOT NULL, city_id INT NOT NULL,
postal_code VARCHAR(10) DEFAULT NULL, postal_code VARCHAR(10) DEFAULT NULL,
phone VARCHAR(20) NOT NULL, phone VARCHAR(20) NOT NULL,
last_update TIMESTAMP NOT NULL, last_update TIMESTAMP,
PRIMARY KEY (address_id), PRIMARY KEY (address_id),
CONSTRAINT fk_address_city FOREIGN KEY (city_id) REFERENCES city (city_id) ON DELETE NO ACTION ON UPDATE CASCADE CONSTRAINT fk_address_city FOREIGN KEY (city_id) REFERENCES city (city_id) ON DELETE NO ACTION ON UPDATE CASCADE
) )
@ -119,71 +76,35 @@ CREATE TABLE address (
CREATE INDEX idx_fk_city_id ON address(city_id) CREATE INDEX idx_fk_city_id ON address(city_id)
; ;
CREATE TRIGGER address_trigger_ai AFTER INSERT ON address
BEGIN
UPDATE address SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER address_trigger_au AFTER UPDATE ON address
BEGIN
UPDATE address SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
-- --
-- Table structure for table language -- Table structure for table language
-- --
CREATE TABLE language ( CREATE TABLE language (
language_id SMALLINT NOT NULL , language_id INTEGER NOT NULL ,
name CHAR(20) NOT NULL, name CHAR(20) NOT NULL,
last_update TIMESTAMP NOT NULL, last_update TIMESTAMP,
PRIMARY KEY (language_id) PRIMARY KEY (language_id)
) )
; ;
CREATE TRIGGER language_trigger_ai AFTER INSERT ON language
BEGIN
UPDATE language SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER language_trigger_au AFTER UPDATE ON language
BEGIN
UPDATE language SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
-- --
-- Table structure for table category -- Table structure for table category
-- --
CREATE TABLE category ( CREATE TABLE category (
category_id SMALLINT NOT NULL, category_id INTEGER NOT NULL,
name VARCHAR(25) NOT NULL, name VARCHAR(25) NOT NULL,
last_update TIMESTAMP NOT NULL, last_update TIMESTAMP,
PRIMARY KEY (category_id) PRIMARY KEY (category_id)
); );
CREATE TRIGGER category_trigger_ai AFTER INSERT ON category
BEGIN
UPDATE category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER category_trigger_au AFTER UPDATE ON category
BEGIN
UPDATE category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
-- --
-- Table structure for table customer -- Table structure for table customer
-- --
CREATE TABLE customer ( CREATE TABLE customer (
customer_id INT NOT NULL, customer_id INTEGER NOT NULL,
store_id INT NOT NULL, store_id INT NOT NULL,
first_name VARCHAR(45) NOT NULL, first_name VARCHAR(45) NOT NULL,
last_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL,
@ -191,7 +112,7 @@ CREATE TABLE customer (
address_id INT NOT NULL, address_id INT NOT NULL,
active CHAR(1) DEFAULT 'Y' NOT NULL, active CHAR(1) DEFAULT 'Y' NOT NULL,
create_date TIMESTAMP NOT NULL, create_date TIMESTAMP NOT NULL,
last_update TIMESTAMP NOT NULL, last_update TIMESTAMP,
PRIMARY KEY (customer_id), PRIMARY KEY (customer_id),
CONSTRAINT fk_customer_store FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT fk_customer_store FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT fk_customer_address FOREIGN KEY (address_id) REFERENCES address (address_id) ON DELETE NO ACTION ON UPDATE CASCADE CONSTRAINT fk_customer_address FOREIGN KEY (address_id) REFERENCES address (address_id) ON DELETE NO ACTION ON UPDATE CASCADE
@ -205,43 +126,30 @@ CREATE INDEX idx_customer_fk_address_id ON customer(address_id)
CREATE INDEX idx_customer_last_name ON customer(last_name) CREATE INDEX idx_customer_last_name ON customer(last_name)
; ;
CREATE TRIGGER customer_trigger_ai AFTER INSERT ON customer
BEGIN
UPDATE customer SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER customer_trigger_au AFTER UPDATE ON customer
BEGIN
UPDATE customer SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
-- --
-- Table structure for table film -- Table structure for table film
-- --
CREATE TABLE film ( CREATE TABLE film (
film_id int NOT NULL, film_id INTEGER NOT NULL,
title VARCHAR(255) NOT NULL, title VARCHAR(255) NOT NULL,
description BLOB SUB_TYPE TEXT DEFAULT NULL, description BLOB SUB_TYPE TEXT DEFAULT NULL,
release_year VARCHAR(4) DEFAULT NULL, release_year VARCHAR(4) DEFAULT NULL,
language_id SMALLINT NOT NULL, language_id INTEGER NOT NULL,
original_language_id SMALLINT DEFAULT NULL, original_language_id INTEGER DEFAULT NULL,
rental_duration SMALLINT DEFAULT 3 NOT NULL, rental_duration INTEGER DEFAULT 3 NOT NULL,
rental_rate DECIMAL(4,2) DEFAULT 4.99 NOT NULL, rental_rate DECIMAL(4,2) DEFAULT 4.99 NOT NULL,
length SMALLINT DEFAULT NULL, length INTEGER DEFAULT NULL,
replacement_cost DECIMAL(5,2) DEFAULT 19.99 NOT NULL, replacement_cost DECIMAL(5,2) DEFAULT 19.99 NOT NULL,
rating VARCHAR(10) DEFAULT 'G', rating VARCHAR(10) DEFAULT 'G',
special_features VARCHAR(100) DEFAULT NULL, special_features VARCHAR(100) DEFAULT NULL,
last_update TIMESTAMP NOT NULL, last_update TIMESTAMP,
PRIMARY KEY (film_id), PRIMARY KEY (film_id),
CONSTRAINT CHECK_special_features CHECK(special_features is null or CONSTRAINT CHECK_special_features CHECK(special_features is null or
special_features like '%Trailers%' or special_features like '%Trailers%' or
special_features like '%Commentaries%' or special_features like '%Commentaries%' or
special_features like '%Deleted Scenes%' or special_features like '%Deleted Scenes%' or
special_features like '%Behind the Scenes%'), special_features like '%Behind the Scenes%'),
CONSTRAINT CHECK_special_rating CHECK(rating in ('G','PG','PG-13','R','NC-17')),
CONSTRAINT fk_film_language FOREIGN KEY (language_id) REFERENCES language (language_id) , CONSTRAINT fk_film_language FOREIGN KEY (language_id) REFERENCES language (language_id) ,
CONSTRAINT fk_film_language_original FOREIGN KEY (original_language_id) REFERENCES language (language_id) CONSTRAINT fk_film_language_original FOREIGN KEY (original_language_id) REFERENCES language (language_id)
) )
@ -251,18 +159,6 @@ CREATE INDEX idx_fk_language_id ON film(language_id)
CREATE INDEX idx_fk_original_language_id ON film(original_language_id) CREATE INDEX idx_fk_original_language_id ON film(original_language_id)
; ;
CREATE TRIGGER film_trigger_ai AFTER INSERT ON film
BEGIN
UPDATE film SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER film_trigger_au AFTER UPDATE ON film
BEGIN
UPDATE film SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
-- --
-- Table structure for table film_actor -- Table structure for table film_actor
-- --
@ -270,7 +166,7 @@ CREATE TRIGGER film_trigger_au AFTER UPDATE ON film
CREATE TABLE film_actor ( CREATE TABLE film_actor (
actor_id INT NOT NULL, actor_id INT NOT NULL,
film_id INT NOT NULL, film_id INT NOT NULL,
last_update TIMESTAMP NOT NULL, last_update TIMESTAMP,
PRIMARY KEY (actor_id,film_id), PRIMARY KEY (actor_id,film_id),
CONSTRAINT fk_film_actor_actor FOREIGN KEY (actor_id) REFERENCES actor (actor_id) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT fk_film_actor_actor FOREIGN KEY (actor_id) REFERENCES actor (actor_id) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT fk_film_actor_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE NO ACTION ON UPDATE CASCADE CONSTRAINT fk_film_actor_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE NO ACTION ON UPDATE CASCADE
@ -283,18 +179,6 @@ CREATE INDEX idx_fk_film_actor_film ON film_actor(film_id)
CREATE INDEX idx_fk_film_actor_actor ON film_actor(actor_id) CREATE INDEX idx_fk_film_actor_actor ON film_actor(actor_id)
; ;
CREATE TRIGGER film_actor_trigger_ai AFTER INSERT ON film_actor
BEGIN
UPDATE film_actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER film_actor_trigger_au AFTER UPDATE ON film_actor
BEGIN
UPDATE film_actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
-- --
-- Table structure for table film_category -- Table structure for table film_category
@ -302,8 +186,8 @@ CREATE TRIGGER film_actor_trigger_au AFTER UPDATE ON film_actor
CREATE TABLE film_category ( CREATE TABLE film_category (
film_id INT NOT NULL, film_id INT NOT NULL,
category_id SMALLINT NOT NULL, category_id INTEGER NOT NULL,
last_update TIMESTAMP NOT NULL, last_update TIMESTAMP,
PRIMARY KEY (film_id, category_id), PRIMARY KEY (film_id, category_id),
CONSTRAINT fk_film_category_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT fk_film_category_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT fk_film_category_category FOREIGN KEY (category_id) REFERENCES category (category_id) ON DELETE NO ACTION ON UPDATE CASCADE CONSTRAINT fk_film_category_category FOREIGN KEY (category_id) REFERENCES category (category_id) ON DELETE NO ACTION ON UPDATE CASCADE
@ -316,24 +200,12 @@ CREATE INDEX idx_fk_film_category_film ON film_category(film_id)
CREATE INDEX idx_fk_film_category_category ON film_category(category_id) CREATE INDEX idx_fk_film_category_category ON film_category(category_id)
; ;
CREATE TRIGGER film_category_trigger_ai AFTER INSERT ON film_category
BEGIN
UPDATE film_category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER film_category_trigger_au AFTER UPDATE ON film_category
BEGIN
UPDATE film_category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
-- --
-- Table structure for table film_text -- Table structure for table film_text
-- --
CREATE TABLE film_text ( CREATE TABLE film_text (
film_id SMALLINT NOT NULL, film_id INTEGER NOT NULL,
title VARCHAR(255) NOT NULL, title VARCHAR(255) NOT NULL,
description BLOB SUB_TYPE TEXT, description BLOB SUB_TYPE TEXT,
PRIMARY KEY (film_id) PRIMARY KEY (film_id)
@ -345,10 +217,10 @@ CREATE TABLE film_text (
-- --
CREATE TABLE inventory ( CREATE TABLE inventory (
inventory_id INT NOT NULL, inventory_id INTEGER NOT NULL,
film_id INT NOT NULL, film_id INT NOT NULL,
store_id INT NOT NULL, store_id INT NOT NULL,
last_update TIMESTAMP NOT NULL, last_update TIMESTAMP,
PRIMARY KEY (inventory_id), PRIMARY KEY (inventory_id),
CONSTRAINT fk_inventory_store FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT fk_inventory_store FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT fk_inventory_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE NO ACTION ON UPDATE CASCADE CONSTRAINT fk_inventory_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE NO ACTION ON UPDATE CASCADE
@ -361,34 +233,22 @@ CREATE INDEX idx_fk_film_id ON inventory(film_id)
CREATE INDEX idx_fk_film_id_store_id ON inventory(store_id,film_id) CREATE INDEX idx_fk_film_id_store_id ON inventory(store_id,film_id)
; ;
CREATE TRIGGER inventory_trigger_ai AFTER INSERT ON inventory
BEGIN
UPDATE inventory SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER inventory_trigger_au AFTER UPDATE ON inventory
BEGIN
UPDATE inventory SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
-- --
-- Table structure for table staff -- Table structure for table staff
-- --
CREATE TABLE staff ( CREATE TABLE staff (
staff_id SMALLINT NOT NULL, staff_id INTEGER NOT NULL,
first_name VARCHAR(45) NOT NULL, first_name VARCHAR(45) NOT NULL,
last_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL,
address_id INT NOT NULL, address_id INT NOT NULL,
picture BLOB DEFAULT NULL, picture BLOB DEFAULT NULL,
email VARCHAR(50) DEFAULT NULL, email VARCHAR(50) DEFAULT NULL,
store_id INT NOT NULL, store_id INT NOT NULL,
active SMALLINT DEFAULT 1 NOT NULL, active INTEGER DEFAULT 1 NOT NULL,
username VARCHAR(16) NOT NULL, username VARCHAR(16) NOT NULL,
password VARCHAR(40) DEFAULT NULL, password VARCHAR(40) DEFAULT NULL,
last_update TIMESTAMP NOT NULL, last_update TIMESTAMP,
PRIMARY KEY (staff_id), PRIMARY KEY (staff_id),
CONSTRAINT fk_staff_store FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT fk_staff_store FOREIGN KEY (store_id) REFERENCES store (store_id) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT fk_staff_address FOREIGN KEY (address_id) REFERENCES address (address_id) ON DELETE NO ACTION ON UPDATE CASCADE CONSTRAINT fk_staff_address FOREIGN KEY (address_id) REFERENCES address (address_id) ON DELETE NO ACTION ON UPDATE CASCADE
@ -400,27 +260,15 @@ CREATE INDEX idx_fk_staff_store_id ON staff(store_id)
CREATE INDEX idx_fk_staff_address_id ON staff(address_id) CREATE INDEX idx_fk_staff_address_id ON staff(address_id)
; ;
CREATE TRIGGER staff_trigger_ai AFTER INSERT ON staff
BEGIN
UPDATE staff SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER staff_trigger_au AFTER UPDATE ON staff
BEGIN
UPDATE staff SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
-- --
-- Table structure for table store -- Table structure for table store
-- --
CREATE TABLE store ( CREATE TABLE store (
store_id INT NOT NULL, store_id INTEGER NOT NULL,
manager_staff_id SMALLINT NOT NULL, manager_staff_id INTEGER NOT NULL,
address_id INT NOT NULL, address_id INT NOT NULL,
last_update TIMESTAMP NOT NULL, last_update TIMESTAMP,
PRIMARY KEY (store_id), PRIMARY KEY (store_id),
CONSTRAINT fk_store_staff FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id) , CONSTRAINT fk_store_staff FOREIGN KEY (manager_staff_id) REFERENCES staff (staff_id) ,
CONSTRAINT fk_store_address FOREIGN KEY (address_id) REFERENCES address (address_id) CONSTRAINT fk_store_address FOREIGN KEY (address_id) REFERENCES address (address_id)
@ -433,30 +281,19 @@ CREATE INDEX idx_store_fk_manager_staff_id ON store(manager_staff_id)
CREATE INDEX idx_fk_store_address ON store(address_id) CREATE INDEX idx_fk_store_address ON store(address_id)
; ;
CREATE TRIGGER store_trigger_ai AFTER INSERT ON store
BEGIN
UPDATE store SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER store_trigger_au AFTER UPDATE ON store
BEGIN
UPDATE store SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
-- --
-- Table structure for table payment -- Table structure for table payment
-- --
CREATE TABLE payment ( CREATE TABLE payment (
payment_id int NOT NULL, payment_id INTEGER NOT NULL,
customer_id INT NOT NULL, customer_id INT NOT NULL,
staff_id SMALLINT NOT NULL, staff_id INTEGER NOT NULL,
rental_id INT DEFAULT NULL, rental_id INT DEFAULT NULL,
amount DECIMAL(5,2) NOT NULL, amount DECIMAL(5,2) NOT NULL,
payment_date TIMESTAMP NOT NULL, payment_date TIMESTAMP NOT NULL,
last_update TIMESTAMP NOT NULL, last_update TIMESTAMP,
PRIMARY KEY (payment_id), PRIMARY KEY (payment_id),
CONSTRAINT fk_payment_rental FOREIGN KEY (rental_id) REFERENCES rental (rental_id) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT fk_payment_rental FOREIGN KEY (rental_id) REFERENCES rental (rental_id) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT fk_payment_customer FOREIGN KEY (customer_id) REFERENCES customer (customer_id) , CONSTRAINT fk_payment_customer FOREIGN KEY (customer_id) REFERENCES customer (customer_id) ,
@ -468,26 +305,15 @@ CREATE INDEX idx_fk_staff_id ON payment(staff_id)
CREATE INDEX idx_fk_customer_id ON payment(customer_id) CREATE INDEX idx_fk_customer_id ON payment(customer_id)
; ;
CREATE TRIGGER payment_trigger_ai AFTER INSERT ON payment
BEGIN
UPDATE payment SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER payment_trigger_au AFTER UPDATE ON payment
BEGIN
UPDATE payment SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TABLE rental ( CREATE TABLE rental (
rental_id INT NOT NULL, rental_id INTEGER NOT NULL,
rental_date TIMESTAMP NOT NULL, rental_date TIMESTAMP NOT NULL,
inventory_id INT NOT NULL, inventory_id INT NOT NULL,
customer_id INT NOT NULL, customer_id INT NOT NULL,
return_date TIMESTAMP DEFAULT NULL, return_date TIMESTAMP DEFAULT NULL,
staff_id SMALLINT NOT NULL, staff_id INTEGER NOT NULL,
last_update TIMESTAMP NOT NULL, last_update TIMESTAMP,
PRIMARY KEY (rental_id), PRIMARY KEY (rental_id),
CONSTRAINT fk_rental_staff FOREIGN KEY (staff_id) REFERENCES staff (staff_id) , CONSTRAINT fk_rental_staff FOREIGN KEY (staff_id) REFERENCES staff (staff_id) ,
CONSTRAINT fk_rental_inventory FOREIGN KEY (inventory_id) REFERENCES inventory (inventory_id) , CONSTRAINT fk_rental_inventory FOREIGN KEY (inventory_id) REFERENCES inventory (inventory_id) ,
@ -503,17 +329,6 @@ CREATE INDEX idx_rental_fk_staff_id ON rental(staff_id)
CREATE UNIQUE INDEX idx_rental_uq ON rental (rental_date,inventory_id,customer_id) CREATE UNIQUE INDEX idx_rental_uq ON rental (rental_date,inventory_id,customer_id)
; ;
CREATE TRIGGER rental_trigger_ai AFTER INSERT ON rental
BEGIN
UPDATE rental SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER rental_trigger_au AFTER UPDATE ON rental
BEGIN
UPDATE rental SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
-- --
-- View structure for view customer_list -- View structure for view customer_list
-- --

92546
packages/nocodb/tests/sqlite-sakila-db/02-sqlite-sakila-insert-data.sql

File diff suppressed because it is too large Load Diff

604
packages/nocodb/tests/sqlite-sakila-db/03-sqlite-prefix-sakila-schema.sql

@ -1,604 +0,0 @@
/*
Sakila for SQLite is a port of the Sakila example database available for MySQL, which was originally developed by Mike Hillyer of the MySQL AB documentation team.
This project is designed to help database administrators to decide which database to use for development of new products
The user can run the same SQL against different kind of databases and compare the performance
License: BSD
Copyright DB Software Laboratory
http://www.etl-tools.com
*/
CREATE TABLE prefix___actor (
actor_id numeric NOT NULL ,
first_name VARCHAR(45) NOT NULL,
last_name VARCHAR(45) NOT NULL,
last_update TIMESTAMP NOT NULL,
PRIMARY KEY (actor_id)
) ;
CREATE INDEX prefix___idx_actor_last_name ON prefix___actor(last_name)
;
CREATE TRIGGER prefix___actor_trigger_ai AFTER INSERT ON prefix___actor
BEGIN
UPDATE prefix___actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___actor_trigger_au AFTER UPDATE ON prefix___actor
BEGIN
UPDATE prefix___actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
--
-- Table structure for table country
--
CREATE TABLE prefix___country (
country_id SMALLINT NOT NULL,
country VARCHAR(50) NOT NULL,
last_update TIMESTAMP,
PRIMARY KEY (country_id)
)
;
CREATE TRIGGER prefix___country_trigger_ai AFTER INSERT ON prefix___country
BEGIN
UPDATE prefix___country SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___country_trigger_au AFTER UPDATE ON prefix___country
BEGIN
UPDATE prefix___country SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
--
-- Table structure for table city
--
CREATE TABLE prefix___city (
city_id int NOT NULL,
city VARCHAR(50) NOT NULL,
country_id SMALLINT NOT NULL,
last_update TIMESTAMP NOT NULL,
PRIMARY KEY (city_id),
CONSTRAINT prefix___fk_city_country FOREIGN KEY (country_id) REFERENCES prefix___country (country_id) ON DELETE NO ACTION ON UPDATE CASCADE
)
;
CREATE INDEX prefix___idx_fk_country_id ON prefix___city(country_id)
;
CREATE TRIGGER prefix___city_trigger_ai AFTER INSERT ON prefix___city
BEGIN
UPDATE prefix___city SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___city_trigger_au AFTER UPDATE ON prefix___city
BEGIN
UPDATE prefix___city SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
--
-- Table structure for table address
--
CREATE TABLE prefix___address (
address_id int NOT NULL,
address VARCHAR(50) NOT NULL,
address2 VARCHAR(50) DEFAULT NULL,
district VARCHAR(20) NOT NULL,
city_id INT NOT NULL,
postal_code VARCHAR(10) DEFAULT NULL,
phone VARCHAR(20) NOT NULL,
last_update TIMESTAMP NOT NULL,
PRIMARY KEY (address_id),
CONSTRAINT prefix___fk_address_city FOREIGN KEY (city_id) REFERENCES prefix___city (city_id) ON DELETE NO ACTION ON UPDATE CASCADE
)
;
CREATE INDEX prefix___idx_fk_city_id ON prefix___address(city_id)
;
CREATE TRIGGER prefix___address_trigger_ai AFTER INSERT ON prefix___address
BEGIN
UPDATE prefix___address SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___address_trigger_au AFTER UPDATE ON prefix___address
BEGIN
UPDATE prefix___address SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
--
-- Table structure for table language
--
CREATE TABLE prefix___language (
language_id SMALLINT NOT NULL ,
name CHAR(20) NOT NULL,
last_update TIMESTAMP NOT NULL,
PRIMARY KEY (language_id)
)
;
CREATE TRIGGER prefix___language_trigger_ai AFTER INSERT ON prefix___language
BEGIN
UPDATE prefix___language SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___language_trigger_au AFTER UPDATE ON prefix___language
BEGIN
UPDATE prefix___language SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
--
-- Table structure for table category
--
CREATE TABLE prefix___category (
category_id SMALLINT NOT NULL,
name VARCHAR(25) NOT NULL,
last_update TIMESTAMP NOT NULL,
PRIMARY KEY (category_id)
);
CREATE TRIGGER prefix___category_trigger_ai AFTER INSERT ON prefix___category
BEGIN
UPDATE prefix___category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___category_trigger_au AFTER UPDATE ON prefix___category
BEGIN
UPDATE prefix___category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
--
-- Table structure for table customer
--
CREATE TABLE prefix___customer (
customer_id INT NOT NULL,
store_id INT NOT NULL,
first_name VARCHAR(45) NOT NULL,
last_name VARCHAR(45) NOT NULL,
email VARCHAR(50) DEFAULT NULL,
address_id INT NOT NULL,
active CHAR(1) DEFAULT 'Y' NOT NULL,
create_date TIMESTAMP NOT NULL,
last_update TIMESTAMP NOT NULL,
PRIMARY KEY (customer_id),
CONSTRAINT prefix___fk_customer_store FOREIGN KEY (store_id) REFERENCES prefix___store (store_id) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT prefix___fk_customer_address FOREIGN KEY (address_id) REFERENCES prefix___address (address_id) ON DELETE NO ACTION ON UPDATE CASCADE
)
;
CREATE INDEX prefix___idx_customer_fk_store_id ON prefix___customer(store_id)
;
CREATE INDEX prefix___idx_customer_fk_address_id ON prefix___customer(address_id)
;
CREATE INDEX prefix___idx_customer_last_name ON prefix___customer(last_name)
;
CREATE TRIGGER prefix___customer_trigger_ai AFTER INSERT ON prefix___customer
BEGIN
UPDATE prefix___customer SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___customer_trigger_au AFTER UPDATE ON prefix___customer
BEGIN
UPDATE prefix___customer SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
--
-- Table structure for table film
--
CREATE TABLE prefix___film (
film_id int NOT NULL,
title VARCHAR(255) NOT NULL,
description BLOB SUB_TYPE TEXT DEFAULT NULL,
release_year VARCHAR(4) DEFAULT NULL,
language_id SMALLINT NOT NULL,
original_language_id SMALLINT DEFAULT NULL,
rental_duration SMALLINT DEFAULT 3 NOT NULL,
rental_rate DECIMAL(4,2) DEFAULT 4.99 NOT NULL,
length SMALLINT DEFAULT NULL,
replacement_cost DECIMAL(5,2) DEFAULT 19.99 NOT NULL,
rating VARCHAR(10) DEFAULT 'G',
special_features VARCHAR(100) DEFAULT NULL,
last_update TIMESTAMP NOT NULL,
PRIMARY KEY (film_id),
CONSTRAINT CHECK_special_features CHECK(special_features is null or
special_features like '%Trailers%' or
special_features like '%Commentaries%' or
special_features like '%Deleted Scenes%' or
special_features like '%Behind the Scenes%'),
CONSTRAINT CHECK_special_rating CHECK(rating in ('G','PG','PG-13','R','NC-17')),
CONSTRAINT prefix___fk_film_language FOREIGN KEY (language_id) REFERENCES prefix___language (language_id) ,
CONSTRAINT prefix___fk_film_language_original FOREIGN KEY (original_language_id) REFERENCES prefix___language (language_id)
)
;
CREATE INDEX prefix___idx_fk_language_id ON prefix___film(language_id)
;
CREATE INDEX prefix___idx_fk_original_language_id ON prefix___film(original_language_id)
;
CREATE TRIGGER prefix___film_trigger_ai AFTER INSERT ON prefix___film
BEGIN
UPDATE prefix___film SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___film_trigger_au AFTER UPDATE ON prefix___film
BEGIN
UPDATE prefix___film SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
--
-- Table structure for table film_actor
--
CREATE TABLE prefix___film_actor (
actor_id INT NOT NULL,
film_id INT NOT NULL,
last_update TIMESTAMP NOT NULL,
PRIMARY KEY (actor_id,film_id),
CONSTRAINT prefix___fk_film_actor_actor FOREIGN KEY (actor_id) REFERENCES prefix___actor (actor_id) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT prefix___fk_film_actor_film FOREIGN KEY (film_id) REFERENCES prefix___film (film_id) ON DELETE NO ACTION ON UPDATE CASCADE
)
;
CREATE INDEX prefix___idx_fk_film_actor_film ON prefix___film_actor(film_id)
;
CREATE INDEX prefix___idx_fk_film_actor_actor ON prefix___film_actor(actor_id)
;
CREATE TRIGGER prefix___film_actor_trigger_ai AFTER INSERT ON prefix___film_actor
BEGIN
UPDATE prefix___film_actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___film_actor_trigger_au AFTER UPDATE ON prefix___film_actor
BEGIN
UPDATE prefix___film_actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
--
-- Table structure for table film_category
--
CREATE TABLE prefix___film_category (
film_id INT NOT NULL,
category_id SMALLINT NOT NULL,
last_update TIMESTAMP NOT NULL,
PRIMARY KEY (film_id, category_id),
CONSTRAINT prefix___fk_film_category_film FOREIGN KEY (film_id) REFERENCES prefix___film (film_id) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT prefix___fk_film_category_category FOREIGN KEY (category_id) REFERENCES prefix___category (category_id) ON DELETE NO ACTION ON UPDATE CASCADE
)
;
CREATE INDEX prefix___idx_fk_film_category_film ON prefix___film_category(film_id)
;
CREATE INDEX prefix___idx_fk_film_category_category ON prefix___film_category(category_id)
;
CREATE TRIGGER prefix___film_category_trigger_ai AFTER INSERT ON prefix___film_category
BEGIN
UPDATE prefix___film_category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___film_category_trigger_au AFTER UPDATE ON prefix___film_category
BEGIN
UPDATE prefix___film_category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
--
-- Table structure for table film_text
--
CREATE TABLE prefix___film_text (
film_id SMALLINT NOT NULL,
title VARCHAR(255) NOT NULL,
description BLOB SUB_TYPE TEXT,
PRIMARY KEY (film_id)
)
;
--
-- Table structure for table inventory
--
CREATE TABLE prefix___inventory (
inventory_id INT NOT NULL,
film_id INT NOT NULL,
store_id INT NOT NULL,
last_update TIMESTAMP NOT NULL,
PRIMARY KEY (inventory_id),
CONSTRAINT prefix___fk_inventory_store FOREIGN KEY (store_id) REFERENCES prefix___store (store_id) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT prefix___fk_inventory_film FOREIGN KEY (film_id) REFERENCES prefix___film (film_id) ON DELETE NO ACTION ON UPDATE CASCADE
)
;
CREATE INDEX prefix___idx_fk_film_id ON prefix___inventory(film_id)
;
CREATE INDEX prefix___idx_fk_film_id_store_id ON prefix___inventory(store_id,film_id)
;
CREATE TRIGGER prefix___inventory_trigger_ai AFTER INSERT ON prefix___inventory
BEGIN
UPDATE prefix___inventory SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___inventory_trigger_au AFTER UPDATE ON prefix___inventory
BEGIN
UPDATE prefix___inventory SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
--
-- Table structure for table staff
--
CREATE TABLE prefix___staff (
staff_id SMALLINT NOT NULL,
first_name VARCHAR(45) NOT NULL,
last_name VARCHAR(45) NOT NULL,
address_id INT NOT NULL,
picture BLOB DEFAULT NULL,
email VARCHAR(50) DEFAULT NULL,
store_id INT NOT NULL,
active SMALLINT DEFAULT 1 NOT NULL,
username VARCHAR(16) NOT NULL,
password VARCHAR(40) DEFAULT NULL,
last_update TIMESTAMP NOT NULL,
PRIMARY KEY (staff_id),
CONSTRAINT prefix___fk_staff_store FOREIGN KEY (store_id) REFERENCES prefix___store (store_id) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT prefix___fk_staff_address FOREIGN KEY (address_id) REFERENCES prefix___address (address_id) ON DELETE NO ACTION ON UPDATE CASCADE
)
;
CREATE INDEX prefix___idx_fk_staff_store_id ON prefix___staff(store_id)
;
CREATE INDEX prefix___idx_fk_staff_address_id ON prefix___staff(address_id)
;
CREATE TRIGGER prefix___staff_trigger_ai AFTER INSERT ON prefix___staff
BEGIN
UPDATE prefix___staff SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___staff_trigger_au AFTER UPDATE ON prefix___staff
BEGIN
UPDATE prefix___staff SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
--
-- Table structure for table store
--
CREATE TABLE prefix___store (
store_id INT NOT NULL,
manager_staff_id SMALLINT NOT NULL,
address_id INT NOT NULL,
last_update TIMESTAMP NOT NULL,
PRIMARY KEY (store_id),
CONSTRAINT prefix___fk_store_staff FOREIGN KEY (manager_staff_id) REFERENCES prefix___staff (staff_id) ,
CONSTRAINT prefix___fk_store_address FOREIGN KEY (address_id) REFERENCES prefix___address (address_id)
)
;
CREATE INDEX prefix___idx_store_fk_manager_staff_id ON prefix___store(manager_staff_id)
;
CREATE INDEX prefix___idx_fk_store_address ON prefix___store(address_id)
;
CREATE TRIGGER prefix___store_trigger_ai AFTER INSERT ON prefix___store
BEGIN
UPDATE prefix___store SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___store_trigger_au AFTER UPDATE ON prefix___store
BEGIN
UPDATE prefix___store SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
--
-- Table structure for table payment
--
CREATE TABLE prefix___payment (
payment_id int NOT NULL,
customer_id INT NOT NULL,
staff_id SMALLINT NOT NULL,
rental_id INT DEFAULT NULL,
amount DECIMAL(5,2) NOT NULL,
payment_date TIMESTAMP NOT NULL,
last_update TIMESTAMP NOT NULL,
PRIMARY KEY (payment_id),
CONSTRAINT prefix___fk_payment_rental FOREIGN KEY (rental_id) REFERENCES prefix___rental (rental_id) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT prefix___fk_payment_customer FOREIGN KEY (customer_id) REFERENCES prefix___customer (customer_id) ,
CONSTRAINT prefix___fk_payment_staff FOREIGN KEY (staff_id) REFERENCES prefix___staff (staff_id)
)
;
CREATE INDEX prefix___idx_fk_staff_id ON prefix___payment(staff_id)
;
CREATE INDEX prefix___idx_fk_customer_id ON prefix___payment(customer_id)
;
CREATE TRIGGER prefix___payment_trigger_ai AFTER INSERT ON prefix___payment
BEGIN
UPDATE prefix___payment SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___payment_trigger_au AFTER UPDATE ON prefix___payment
BEGIN
UPDATE prefix___payment SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TABLE prefix___rental (
rental_id INT NOT NULL,
rental_date TIMESTAMP NOT NULL,
inventory_id INT NOT NULL,
customer_id INT NOT NULL,
return_date TIMESTAMP DEFAULT NULL,
staff_id SMALLINT NOT NULL,
last_update TIMESTAMP NOT NULL,
PRIMARY KEY (rental_id),
CONSTRAINT prefix___fk_rental_staff FOREIGN KEY (staff_id) REFERENCES prefix___staff (staff_id) ,
CONSTRAINT prefix___fk_rental_inventory FOREIGN KEY (inventory_id) REFERENCES prefix___inventory (inventory_id) ,
CONSTRAINT prefix___fk_rental_customer FOREIGN KEY (customer_id) REFERENCES prefix___customer (customer_id)
)
;
CREATE INDEX prefix___idx_rental_fk_inventory_id ON prefix___rental(inventory_id)
;
CREATE INDEX prefix___idx_rental_fk_customer_id ON prefix___rental(customer_id)
;
CREATE INDEX prefix___idx_rental_fk_staff_id ON prefix___rental(staff_id)
;
CREATE UNIQUE INDEX prefix___idx_rental_uq ON prefix___rental (rental_date,inventory_id,customer_id)
;
CREATE TRIGGER prefix___rental_trigger_ai AFTER INSERT ON prefix___rental
BEGIN
UPDATE prefix___rental SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
CREATE TRIGGER prefix___rental_trigger_au AFTER UPDATE ON prefix___rental
BEGIN
UPDATE prefix___rental SET last_update = DATETIME('NOW') WHERE rowid = new.rowid
END
;
--
-- View structure for view customer_list
--
CREATE VIEW prefix___customer_list
AS
SELECT cu.customer_id AS ID,
cu.first_name||' '||cu.last_name AS name,
a.address AS address,
a.postal_code AS zip_code,
a.phone AS phone,
prefix___city.city AS city,
prefix___country.country AS country,
case when cu.active=1 then 'active' else '' end AS notes,
cu.store_id AS SID
FROM prefix___customer AS cu JOIN prefix___address AS a ON cu.address_id = a.address_id JOIN prefix___city ON a.city_id = prefix___city.city_id
JOIN prefix___country ON prefix___city.country_id = prefix___country.country_id
;
--
-- View structure for view film_list
--
CREATE VIEW prefix___film_list
AS
SELECT prefix___film.film_id AS FID,
prefix___film.title AS title,
prefix___film.description AS description,
prefix___category.name AS category,
prefix___film.rental_rate AS price,
prefix___film.length AS length,
prefix___film.rating AS rating,
prefix___actor.first_name||' '||prefix___actor.last_name AS actors
FROM prefix___category LEFT JOIN prefix___film_category ON prefix___category.category_id = prefix___film_category.category_id LEFT JOIN prefix___film ON prefix___film_category.film_id = prefix___film.film_id
JOIN prefix___film_actor ON prefix___film.film_id = prefix___film_actor.film_id
JOIN prefix___actor ON prefix___film_actor.actor_id = prefix___actor.actor_id
;
--
-- View structure for view staff_list
--
CREATE VIEW prefix___staff_list
AS
SELECT s.staff_id AS ID,
s.first_name||' '||s.last_name AS name,
a.address AS address,
a.postal_code AS zip_code,
a.phone AS phone,
prefix___city.city AS city,
prefix___country.country AS country,
s.store_id AS SID
FROM prefix___staff AS s JOIN prefix___address AS a ON s.address_id = a.address_id JOIN prefix___city ON a.city_id = prefix___city.city_id
JOIN prefix___country ON prefix___city.country_id = prefix___country.country_id
;
--
-- View structure for view sales_by_store
--
CREATE VIEW prefix___sales_by_store
AS
SELECT
s.store_id
,c.city||','||cy.country AS store
,m.first_name||' '||m.last_name AS manager
,SUM(p.amount) AS total_sales
FROM prefix___payment AS p
INNER JOIN prefix___rental AS r ON p.rental_id = r.rental_id
INNER JOIN prefix___inventory AS i ON r.inventory_id = i.inventory_id
INNER JOIN prefix___store AS s ON i.store_id = s.store_id
INNER JOIN prefix___address AS a ON s.address_id = a.address_id
INNER JOIN prefix___city AS c ON a.city_id = c.city_id
INNER JOIN prefix___country AS cy ON c.country_id = cy.country_id
INNER JOIN prefix___staff AS m ON s.manager_staff_id = m.staff_id
GROUP BY
s.store_id
, c.city||','||cy.country
, m.first_name||' '||m.last_name
;
--
-- View structure for view sales_by_film_category
--
-- Note that total sales will add up to >100% because
-- some titles belong to more than 1 category
--
CREATE VIEW prefix___sales_by_film_category
AS
SELECT
c.name AS category
, SUM(p.amount) AS total_sales
FROM prefix___payment AS p
INNER JOIN prefix___rental AS r ON p.rental_id = r.rental_id
INNER JOIN prefix___inventory AS i ON r.inventory_id = i.inventory_id
INNER JOIN prefix___film AS f ON i.film_id = f.film_id
INNER JOIN prefix___film_category AS fc ON f.film_id = fc.film_id
INNER JOIN prefix___category AS c ON fc.category_id = c.category_id
GROUP BY c.name
;

180
packages/nocodb/tests/sqlite-sakila-db/03-sqlite-sakila-triggers.sql

@ -0,0 +1,180 @@
CREATE TRIGGER actor_trigger_ai AFTER INSERT ON actor
BEGIN
UPDATE actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER actor_trigger_au AFTER UPDATE ON actor
BEGIN
UPDATE actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER country_trigger_ai AFTER INSERT ON country
BEGIN
UPDATE country SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER country_trigger_au AFTER UPDATE ON country
BEGIN
UPDATE country SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER city_trigger_ai AFTER INSERT ON city
BEGIN
UPDATE city SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER city_trigger_au AFTER UPDATE ON city
BEGIN
UPDATE city SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER address_trigger_ai AFTER INSERT ON address
BEGIN
UPDATE address SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER address_trigger_au AFTER UPDATE ON address
BEGIN
UPDATE address SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER language_trigger_ai AFTER INSERT ON language
BEGIN
UPDATE language SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER language_trigger_au AFTER UPDATE ON language
BEGIN
UPDATE language SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER category_trigger_ai AFTER INSERT ON category
BEGIN
UPDATE category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER category_trigger_au AFTER UPDATE ON category
BEGIN
UPDATE category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER customer_trigger_ai AFTER INSERT ON customer
BEGIN
UPDATE customer SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER customer_trigger_au AFTER UPDATE ON customer
BEGIN
UPDATE customer SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER film_trigger_ai AFTER INSERT ON film
BEGIN
UPDATE film SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER film_trigger_au AFTER UPDATE ON film
BEGIN
UPDATE film SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER film_actor_trigger_ai AFTER INSERT ON film_actor
BEGIN
UPDATE film_actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER film_actor_trigger_au AFTER UPDATE ON film_actor
BEGIN
UPDATE film_actor SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER film_category_trigger_ai AFTER INSERT ON film_category
BEGIN
UPDATE film_category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER film_category_trigger_au AFTER UPDATE ON film_category
BEGIN
UPDATE film_category SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER inventory_trigger_ai AFTER INSERT ON inventory
BEGIN
UPDATE inventory SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER inventory_trigger_au AFTER UPDATE ON inventory
BEGIN
UPDATE inventory SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER staff_trigger_ai AFTER INSERT ON staff
BEGIN
UPDATE staff SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER staff_trigger_au AFTER UPDATE ON staff
BEGIN
UPDATE staff SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER store_trigger_ai AFTER INSERT ON store
BEGIN
UPDATE store SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER store_trigger_au AFTER UPDATE ON store
BEGIN
UPDATE store SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER payment_trigger_ai AFTER INSERT ON payment
BEGIN
UPDATE payment SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER payment_trigger_au AFTER UPDATE ON payment
BEGIN
UPDATE payment SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER rental_trigger_ai AFTER INSERT ON rental
BEGIN
UPDATE rental SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;
CREATE TRIGGER rental_trigger_au AFTER UPDATE ON rental
BEGIN
UPDATE rental SET last_update = DATETIME('NOW') WHERE rowid = new.rowid;
END
;

231486
packages/nocodb/tests/sqlite-sakila-db/04-sqlite-prefix-sakila-insert-data.sql

File diff suppressed because it is too large Load Diff

BIN
packages/nocodb/tests/sqlite-sakila-db/sakila.db

Binary file not shown.

BIN
packages/nocodb/tests/sqlite-sakila-db/sakila_v2.db

Binary file not shown.
Loading…
Cancel
Save