text: DROP DATABASE IF EXISTS foodfydb
  CREATE DATABASE foodfydb
  
  CREATE TABLE "users" (
    "id" SERIAL PRIMARY KEY,
    "name" text NOT NULL,
    "email" text UNIQUE NOT NULL,
    "password" text NOT NULL,
    "reset_token" TEXT,
    "reset_token_expires" TEXT,
    "is_admin" BOOLEAN DEFAULT false NOT NULL,
    "created_at" timestamp DEFAULT (now()),
    "updated_at" timestamp DEFAULT (now())
  );
  
  CREATE TABLE "chefs" (
    "id" SERIAL PRIMARY KEY,
    "name" text,
    "created_at" timestamp DEFAULT (now()),
    "file_id" INT NOT NULL
  );
  
  CREATE TABLE "files" (
    "id" SERIAL PRIMARY KEY,
    "name" text,
    "path" text NOT NULL
  );
  
  CREATE TABLE "recipes" (
    "id" SERIAL PRIMARY KEY,
    "chef_id" INTEGER REFERENCES chefs(id),
    "title" text,
    "ingredients" text[],
    "preparation" text[],
    "information" text,
    "status" text,
    "created_at" timestamp DEFAULT (now()),
    "updated_at" timestamp DEFAULT (now()),
    "user_id" INTEGER REFERENCES users(id) 
    
  );
  
  CREATE TABLE "recipe_files" (
    "id" SERIAL PRIMARY KEY,
    "recipe_id" int REFERENCES recipes(id) ON DELETE CASCADE,
    "file_id" int REFERENCES files(id) ON DELETE CASCADE
  );
  
  
  -- foreign key 
  ALTER TABLE "chefs" ADD FOREIGN KEY ("file_id") REFERENCES "files"("id") ON DELETE CASCADE
  
  
  -- create Procedure
  CREATE FUNCTION trigger_set_timestamp()
  RETURNS TRIGGER AS $$
  BEGIN
    NEW.updated_at =NOW();
    RETURN NEW;
  END;
  $$ LANGUAGE plpgsql;
  
  -- Auto updated_at recipes
  CREATE TRIGGER set_timestamp
  BEFORE UPDATE ON recipes
  FOR EACH ROW
  EXECUTE PROCEDURE trigger_set_timestamp();
  
  
  -- Connect pg simple table
  CREATE TABLE "session" (
    "sid" varchar NOT NULL COLLATE "default",
    "sess" json NOT NULL,
    "expire" timestamp(6) NOT NULL
  )
  WITH (OIDS=FALSE);
  ALTER TABLE "session" 
  ADD CONSTRAINT "session_pkey" 
  PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE;
  
  
  --to run seeds
  DELETE FROM recipes;
  DELETE FROM users;
  DELETE FROM chefs;
  DELETE FROM files;
  DELETE FROM recipe_files;
  
  --restart sequence auto_increment from tables ids
  ALTER SEQUENCE recipes_id_seq RESTART WITH 1;
  ALTER SEQUENCE users_id_seq RESTART WITH 1;
  ALTER SEQUENCE chefs_id_seq RESTART WITH 1;
  ALTER SEQUENCE files_id_seq RESTART WITH 1;
  ALTER SEQUENCE recipe_files_id_seq RESTART WITH 1;