BEGIN;
CREATE TABLE "bike_ride" (
"id" serial NOT NULL PRIMARY KEY,
"date" date NOT NULL,
"bike_id" integer NOT NULL,
"origin_id" integer NOT NULL,
"destination_id" integer NOT NULL,
"distance" double precision NOT NULL,
"average_speed" double precision NOT NULL,
"fastest_speed" double precision NOT NULL,
"hours" integer NOT NULL,
"minutes" integer NOT NULL,
"seconds" integer NOT NULL
);
CREATE TABLE "bike_bike" (
"id" serial NOT NULL PRIMARY KEY,
"short_name" varchar(100) NOT NULL,
"description" text NOT NULL
);
ALTER TABLE "bike_ride" ADD CONSTRAINT bike_id_refs_id_6cd188d2 FOREIGN KEY ("bike_id") REFERENCES "bike_bike" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE TABLE "bike_location" (
"id" serial NOT NULL PRIMARY KEY,
"short_name" varchar(100) NOT NULL,
"address" text NOT NULL
);
ALTER TABLE "bike_ride" ADD CONSTRAINT origin_id_refs_id_408dbdcc FOREIGN KEY ("origin_id") REFERENCES "bike_location" ("id") DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE "bike_ride" ADD CONSTRAINT destination_id_refs_id_408dbdcc FOREIGN KEY ("destination_id") REFERENCES "bike_location" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX "bike_ride_bike_id" ON "bike_ride" ("bike_id");
CREATE INDEX "bike_ride_origin_id" ON "bike_ride" ("origin_id");
CREATE INDEX "bike_ride_destination_id" ON "bike_ride" ("destination_id");
COMMIT;