
-- Right

create sequence right_seq start 25;

create table x_right (
	right_id 			bigint 			PRIMARY KEY,
	code			    varchar(50) 	NOT NULL,
	name 	     		varchar(150) 	NOT NULL,
	jpa_active          boolean        	NOT NULL,
    jpa_created         timestamp      	NOT NULL,
    jpa_updated         timestamp      	NOT NULL,
    jpa_version         integer        	NOT NULL,
	CONSTRAINT unq_x_right_code UNIQUE(code)
);


-- user

create sequence user_seq start 25;

create table x_user (
	user_id				bigint 			PRIMARY KEY,
	username			varchar(150) 	NOT NULL,
	password 	    	varchar(150) 	NOT NULL,
	salt	 	   	 	varchar(150) 	NOT NULL,
	title				varchar(15) 	,
	firstname			varchar(150) 	NOT NULL,
	lastname			varchar(150) 	NOT NULL,
	email				varchar(150) 	NOT NULL,
	jpa_active          boolean        	NOT NULL,
    jpa_created         timestamp      	NOT NULL,
    jpa_updated         timestamp      	NOT NULL,
    jpa_version         integer        	NOT NULL,
	CONSTRAINT unq_x_user_username UNIQUE(username)
);

create table user_to_right (
	user_id_fk 		bigint 			REFERENCES x_user,
	right_id_fk 	bigint 	        REFERENCES x_right,
	PRIMARY KEY(user_id_fk, right_id_fk) 
);


-- customer

create sequence customer_seq start 25;

create table customer (
	customer_id			bigint 			PRIMARY KEY,
	customer_number		varchar(150) 	NOT NULL,
	name 	    	    varchar(150) 	NOT NULL,
	jpa_active          boolean        	NOT NULL,
    jpa_created         timestamp      	NOT NULL,
    jpa_updated         timestamp      	NOT NULL,
    jpa_version         integer        	NOT NULL,
	CONSTRAINT unq_customer_number UNIQUE(customer_number)
);


-- picture

create sequence picture_seq start 25;

create table picture (
	picture_id			bigint 			PRIMARY KEY,
	username			varchar(150),
	picture_date        timestamp      	NOT NULL,
	comment 	    	TEXT,
	image 	    	    TEXT,
	jpa_active          boolean        	NOT NULL,
    jpa_created         timestamp      	NOT NULL,
    jpa_updated         timestamp      	NOT NULL,
    jpa_version         integer        	NOT NULL,
    customer_id_fk		bigint			REFERENCES customer
);