From a2dc832229534bd6349e6767be722e670424c819 Mon Sep 17 00:00:00 2001 From: LEV Date: Tue, 11 Oct 2016 15:35:31 +0300 Subject: [PATCH] create db and tables --- Vagrantfile | 2 +- dumps/students/s_06/schema.sql | 60 ++++++++++++++++++++++++++++++++++ insertData.sh | 24 +++++++------- 3 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 dumps/students/s_06/schema.sql diff --git a/Vagrantfile b/Vagrantfile index 60ac666..d49a217 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -5,7 +5,7 @@ Vagrant.configure(2) do |config| config.vm.box = "ubuntu/trusty64" config.vm.network "forwarded_port", guest: 80, host: 8080 config.vm.network "private_network", ip: "192.168.33.16" - config.vm.synced_folder "./", "/home/vagrant/", create: true, :nfs => true + config.vm.synced_folder "./", "/home/vagrant/", create: true config.vm.provider "virtualbox" do |vb| vb.memory = "512" end diff --git a/dumps/students/s_06/schema.sql b/dumps/students/s_06/schema.sql new file mode 100644 index 0000000..6916ede --- /dev/null +++ b/dumps/students/s_06/schema.sql @@ -0,0 +1,60 @@ +DROP TABLE IF EXISTS guns CASCADE; +DROP TABLE IF EXISTS users CASCADE; +DROP TABLE IF EXISTS personals CASCADE; +DROP TABLE IF EXISTS roles CASCADE; +DROP TABLE IF EXISTS sales CASCADE; +DROP TABLE IF EXISTS users_guns CASCADE; +DROP TABLE IF EXISTS kalibers CASCADE; +DROP TABLE IF EXISTS gun_types CASCADE; + +CREATE TABLE gun_types( + id SERIAL PRIMARY KEY, + name VARCHAR(50) NOT NULL, +); + +CREATE TABLE users( + id SERIAL PRIMARY KEY, + first_name VARCHAR(50) NOT NULL, + second_name VARCHAR(50) NOT NULL, + licence VARCHAR(50) NOT NULL, + passport_data VARCHAR(50) NOT NULL +); + +CREATE TABLE kalibers( + id SERIAL PRIMARY KEY, + name VARCHAR(50) NOT NULL +); + +CREATE TABLE roles( + id SERIAL PRIMARY KEY, + name VARCHAR(50) NOT NULL +); + +CREATE TABLE guns( + id SERIAL PRIMARY KEY, + name VARCHAR(50) NOT NULL, + gun_type_id INT REFERENCES gun_types (id) +); + + +CREATE TABLE personals( + id SERIAL PRIMARY KEY, + first_name VARCHAR(50) NOT NULL, + second_name VARCHAR(50) NOT NULL, + born_year SMALLINT NOT NULL CONSTRAINT positive_age CHECK (born_year > 0), + roles_id INT REFERENCES roles (id) +); + + +CREATE TABLE sales( + id SERIAL PRIMARY KEY, + users_id INT REFERENCES users (id), + price VARCHAR(50) NOT NULL +); + + +CREATE TABLE users_guns( + id SERIAL PRIMARY KEY, + users_id INT REFERENCES users (id), + gun_id INT REFERENCES guns (id) +); diff --git a/insertData.sh b/insertData.sh index 14db6a6..9f3aaaa 100755 --- a/insertData.sh +++ b/insertData.sh @@ -1,13 +1,13 @@ #!/bin/bash -i -PGPASSWORD='12345678' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/countries.sql -PGPASSWORD='12345678' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/cities.sql -PGPASSWORD='12345678' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/districts.sql -PGPASSWORD='12345678' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/buildings.sql -PGPASSWORD='12345678' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/criminal_group_types.sql -PGPASSWORD='12345678' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/criminal_groups.sql -PGPASSWORD='12345678' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/persons.sql -PGPASSWORD='12345678' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/persons_enemies.sql -PGPASSWORD='12345678' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/persons_allies.sql -PGPASSWORD='12345678' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/persons_criminal_groups.sql -PGPASSWORD='12345678' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/super_abilities.sql -PGPASSWORD='12345678' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/persons_super_abilities.sql +PGPASSWORD='15011992' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/countries.sql +PGPASSWORD='15011992' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/cities.sql +PGPASSWORD='15011992' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/districts.sql +PGPASSWORD='15011992' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/buildings.sql +PGPASSWORD='15011992' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/criminal_group_types.sql +PGPASSWORD='15011992' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/criminal_groups.sql +PGPASSWORD='15011992' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/persons.sql +PGPASSWORD='15011992' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/persons_enemies.sql +PGPASSWORD='15011992' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/persons_allies.sql +PGPASSWORD='15011992' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/persons_criminal_groups.sql +PGPASSWORD='15011992' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/super_abilities.sql +PGPASSWORD='15011992' psql -h localhost -d superhumans -U root -p 5432 -a -q -f /home/vagrant/dumps/persons_super_abilities.sql