PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "Trips" (
	"TripID"	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
	"UserID"	INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS "Users" (
	"UserID"	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
	"Username"	TEXT NOT NULL UNIQUE,
	"Password"	TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS "TicketLegs" (
	"TicketLegID"	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
	"TicketID"	INTEGER
	"UserID"	INTEGER NOT NULL,
	"TrainType"	TEXT NOT NULL,
	"TrainNr"	INTEGER NOT NULL,
	"DepStationID"	INTEGER NOT NULL,
	"DepStation"	TEXT NOT NULL,
	"DepTime"	TEXT NOT NULL,
	"ArrStationID"	INTEGER NOT NULL,
	"ArrStation"	TEXT NOT NULL,
	"ArrTime"	TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS "Tickets" (
	"TicketID"	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
	"UserID"	INTEGER NOT NULL,
	"OrderID"	TEXT NOT NULL UNIQUE,
	"TicketInfo"	TEXT NOT NULL,
	"TicketQR"	BLOB NOT NULL,
	"TicketPkPass"	BLOB NOT NULL,
	"TicketSecCode"	BLOB NOT NULL,
	"Traveller"	TEXT
);
CREATE TABLE IF NOT EXISTS "Cards" (
	"CardID"	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
	"OrderID"	TEXT NOT NULL,
	"UserID"	INTEGER NOT NULL,
	"CardNumber"	TEXT NOT NULL,
	"Class"	INTEGER NOT NULL,
	"Value"	INTEGER NOT NULL,
	"Traveller"	TEXT NOT NULL,
	"CardQR"	BLOB NOT NULL,
	"CardSecCode"	BLOB NOT NULL,
	"CardImage"	BLOB NOT NULL,
	"CardInfo"	TEXT NOT NULL,
	"ValidFrom"	TEXT NOT NULL,
	"ValidTo"	TEXT NOT NULL,
	"QRValidTo"	TEXT NOT NULL,
	"QRValidFrom"	TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS "Legs" (
	"LegID"	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
	"TripID"	INTEGER NOT NULL,
	"UserID"	INTEGER NOT NULL,
	"TrainType"	TEXT NOT NULL,
	"TrainNr"	INTEGER NOT NULL,
	"DepStationID"	INTEGER NOT NULL,
	"DepStation"	TEXT NOT NULL,
	"DepTime"	TEXT NOT NULL,
	"ArrStationID"	INTEGER NOT NULL,
	"ArrStation"	TEXT NOT NULL,
	"ArrTime"	TEXT NOT NULL,
	"TicketID"	INTEGER,
	"Comment"	TEXT
);
DELETE FROM sqlite_sequence;
INSERT INTO sqlite_sequence VALUES('Trips',68);
INSERT INTO sqlite_sequence VALUES('Users',55);
INSERT INTO sqlite_sequence VALUES('TicketLegs',10);
INSERT INTO sqlite_sequence VALUES('Tickets',25);
INSERT INTO sqlite_sequence VALUES('Cards',10);
INSERT INTO sqlite_sequence VALUES('Legs',0);
COMMIT;
