CREATE TABLE sqlite_sequence(name,seq);
CREATE TABLE IF NOT EXISTS "iafd_performers" (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    gender TEXT,
    birthday TEXT,
    astrology TEXT,
    birthplace TEXT,
    years_active TEXT,
    ethnicity TEXT,
    nationality TEXT,
    hair_colors TEXT, 
    eye_color TEXT,
    height_str TEXT,
    weight_str TEXT,  
    measurements TEXT,
    tattoos TEXT,
    piercings TEXT,  
    fake_tits TEXT,
    href TEXT UNIQUE,  
    created_at TEXT DEFAULT (datetime('now', 'localtime')),
    updated_at TEXT DEFAULT (datetime('now', 'localtime')),
    weight INTEGER, 
    height INTEGER,
    rating INTEGER, 
    movies_cnt INTEGER,
    vixen_cnt INTEGER,
    blacked_cnt INTEGER,
    tushy_cnt INTEGER,
    x_art_cnt INTEGER
);
CREATE TABLE IF NOT EXISTS "iafd_performer_aliases" (
  `performer_id` integer NOT NULL,
  `alias` varchar(255) NOT NULL,
  foreign key(`performer_id`) references "iafd_performers"(`id`) on delete CASCADE,
  PRIMARY KEY(`performer_id`, `alias`)
);
CREATE TABLE IF NOT EXISTS "iafd_movies_appers_in" (
  `movie_id` integer,
  `appears_in_id` integer,
  `gradation` integer,  
  `notes` varchar(255),  
  foreign key(`movie_id`) references "iafd_movies"(`id`) on delete CASCADE,
  foreign key(`appears_in_id`) references "iafd_movies"(`id`) on delete CASCADE,
  PRIMARY KEY (`movie_id`, `appears_in_id`)
);
CREATE TABLE IF NOT EXISTS "iafd_performer_urls" (
  `performer_id` integer NOT NULL,
  `position` varchar(255) NOT NULL,
  `url` varchar(255) NOT NULL,
  foreign key(`performer_id`) references "iafd_performers"(`id`) on delete CASCADE,
  PRIMARY KEY(`performer_id`, `position`, `url`)
);
CREATE TABLE IF NOT EXISTS "iafd_distributors" (
  `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  `name` VARCHAR(255) NOT NULL,
  `href` VARCHAR(255) UNIQUE,
  `parent_id` INTEGER DEFAULT NULL CHECK (`id` IS NOT `parent_id`) REFERENCES "iafd_distributors"(`id`) ON DELETE SET NULL,
  `created_at` TEXT DEFAULT (datetime('now', 'localtime')),
  `updated_at` TEXT DEFAULT (datetime('now', 'localtime')),
  `details` TEXT
);
CREATE TABLE IF NOT EXISTS "iafd_studios" (
  `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  `name` VARCHAR(255) NOT NULL,
  `href` VARCHAR(255) UNIQUE,
  `parent_id` INTEGER DEFAULT NULL CHECK (`id` IS NOT `parent_id`) REFERENCES "iafd_studios"(`id`) ON DELETE SET NULL,
  `created_at` TEXT DEFAULT (datetime('now', 'localtime')),
  `updated_at` TEXT DEFAULT (datetime('now', 'localtime')),
  `details` TEXT
);
CREATE TABLE IF NOT EXISTS "iafd_performers_movies" (
  `performer_id` integer,
  `movie_id` integer,
  `role` varchar(255),
  `notes` varchar(255),  
  `created_at` TEXT DEFAULT (datetime('now', 'localtime')),
  foreign key(`performer_id`) references "iafd_performers"(`id`) on delete CASCADE,
  foreign key(`movie_id`) references "iafd_movies"(`id`) on delete CASCADE,
  PRIMARY KEY (`movie_id`, `performer_id`)
);
CREATE TABLE IF NOT EXISTS "iafd_task_log" (
  `task_id` integer not null primary key autoincrement,
  `before_performers` integer,
  `new_performers` integer,
  `after_performers` integer,
  `before_movies` integer,
  `new_movies` integer,
  `after_movies` integer,
  `before_distributors` integer,
  `new_distributors` integer,
  `after_distributors` integer,
  `before_studios` integer,
  `new_studios` integer,
  `after_studios` integer,
  `task_status` varchar(255),
  `created_at` TEXT DEFAULT (datetime('now', 'localtime')),
  `updated_at` TEXT DEFAULT (datetime('now', 'localtime'))
);
CREATE TABLE IF NOT EXISTS "iafd_movies" (
  `id` integer not null primary key autoincrement,
  `title` varchar(255),
  `minutes` varchar(255),
  `distributor_id` integer,
  `studio_id` integer,
  `release_date` varchar(255),
  `added_to_IAFD_date` varchar(255),
  `all_girl` varchar(255),
  `all_male` varchar(255),
  `compilation` varchar(255),
  `webscene` varchar(255),
  `director_id` integer,
  `href` varchar(255) UNIQUE,
  `created_at` TEXT DEFAULT (datetime('now', 'localtime')),
  `updated_at` TEXT DEFAULT (datetime('now', 'localtime')),  
  foreign key(`studio_id`) references "iafd_studios"(`id`) on delete SET NULL,
  foreign key(`distributor_id`) references "iafd_distributors"(`id`) on delete SET NULL  
);
CREATE TABLE javhd_models (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    rank INTEGER,
    ja_name TEXT,
    zh_name TEXT,
    en_name TEXT,
    url TEXT UNIQUE,
    pic TEXT,
    height TEXT,
    weight TEXT,
    breast_size TEXT,
    breast_factor TEXT,
    hair_color TEXT,
    eye_color TEXT,
    birth_date TEXT,
    ethnicity TEXT,
    birth_place TEXT,
    created_at TEXT DEFAULT (datetime('now', 'localtime')),
    updated_at TEXT DEFAULT (datetime('now', 'localtime'))
);
CREATE TABLE thelordofporn_actress (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            pornstar TEXT,
            rating REAL,
            rank INTEGER,
            votes INTEGER,
            href TEXT UNIQUE,
            career_start TEXT,
            measurements TEXT,
            born TEXT,
            height TEXT,
            weight TEXT,
            date_modified TEXT,
            global_rank INTEGER,
            weekly_rank INTEGER,
            last_month_rating REAL,
            current_rating REAL,
            total_votes INTEGER,
            birth_date TEXT,
            birth_year TEXT,
            birth_place TEXT,
            height_ft TEXT,
            height_cm TEXT,
            weight_lbs TEXT,
            weight_kg TEXT,
            created_at TEXT DEFAULT (datetime('now', 'localtime')),
            updated_at TEXT DEFAULT (datetime('now', 'localtime'))
        );
CREATE TABLE thelordofporn_alias (
            actress_id INTEGER NOT NULL,
            alias TEXT NOT NULL,
            FOREIGN KEY (actress_id) REFERENCES thelordofporn_actress(id) ON DELETE CASCADE,
            PRIMARY KEY(`actress_id`, `alias`)
        );
