CREATE TABLE account (id INT AUTO_INCREMENT, name VARCHAR(75) NOT NULL, nickname VARCHAR(40), site_id VARCHAR(2) DEFAULT 'BD' NOT NULL, bill_address VARCHAR(100), bill_address2 VARCHAR(100), bill_city VARCHAR(50), bill_zone_id INT, bill_postcode VARCHAR(20), bill_country_id VARCHAR(2) DEFAULT 'US', ship_address VARCHAR(100), ship_address2 VARCHAR(100), ship_city VARCHAR(50), ship_zone_id INT, ship_postcode VARCHAR(20), ship_country_id VARCHAR(2) DEFAULT 'US', phone VARCHAR(20), phone_alt VARCHAR(20), fax VARCHAR(20), email VARCHAR(100), website VARCHAR(100), quickbooks_listid VARCHAR(25), employee_id INT, account_type_id VARCHAR(1), offers_install TINYINT(1) DEFAULT '0', roundpofootage TINYINT(1) DEFAULT '0', no_employees MEDIUMINT, no_locations MEDIUMINT, campaign_id INT, annual_revenue VARCHAR(10), description TEXT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX account_type_id_idx (account_type_id), INDEX bill_zone_id_idx (bill_zone_id), INDEX bill_country_id_idx (bill_country_id), INDEX campaign_id_idx (campaign_id), INDEX employee_id_idx (employee_id), INDEX ship_zone_id_idx (ship_zone_id), INDEX ship_country_id_idx (ship_country_id), INDEX site_id_idx (site_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE note (id BIGINT AUTO_INCREMENT, message TEXT, parent_type VARCHAR(20), parent_id INT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE account_type (id VARCHAR(1), name VARCHAR(25), globally_vis TINYINT(1), deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE account_warehouse (id INT AUTO_INCREMENT, account_id INT, warehouse_id INT, deleted_at DATETIME, INDEX account_id_idx (account_id), INDEX warehouse_id_idx (warehouse_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE address (id INT AUTO_INCREMENT, first_name VARCHAR(75), last_name VARCHAR(75), company VARCHAR(150), address VARCHAR(100), address2 VARCHAR(100), city VARCHAR(50) NOT NULL, zone_id INT NOT NULL, postcode VARCHAR(20) NOT NULL, country_id VARCHAR(2) DEFAULT 'US' NOT NULL, contact_id INT, location_type_id TINYINT DEFAULT '1' NOT NULL, phone_id BIGINT, phone_alt_id BIGINT, in_address_book TINYINT(1), edit_locked TINYINT(1) DEFAULT '0', deleted_at DATETIME, INDEX phone_id_idx (phone_id), INDEX phone_alt_id_idx (phone_alt_id), INDEX contact_id_idx (contact_id), INDEX country_id_idx (country_id), INDEX location_type_id_idx (location_type_id), INDEX zone_id_idx (zone_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE address_book (id INT AUTO_INCREMENT, contact_id INT, PRIMARY KEY(id, contact_id)) ENGINE = INNODB;
CREATE TABLE attribute_set (id INT AUTO_INCREMENT, name VARCHAR(255) NOT NULL, deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE attribute_set_product_attribute (id TINYINT AUTO_INCREMENT, attribute_set_id INT, product_attribute_id INT, deleted_at DATETIME, INDEX attribute_set_id_idx (attribute_set_id), INDEX product_attribute_id_idx (product_attribute_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE campaign (id INT AUTO_INCREMENT, name VARCHAR(50), details TEXT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE claim (id INT AUTO_INCREMENT, order_shipment_id INT, type VARCHAR(255), status VARCHAR(255) DEFAULT 'Active', description TEXT, result VARCHAR(255) DEFAULT 'Pending', filed TINYINT(1) DEFAULT '0', deleted_at DATETIME, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX order_shipment_id_idx (order_shipment_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE claim_file (id INT AUTO_INCREMENT, claim_id INT, file_location VARCHAR(150) DEFAULT 'claim', file_name VARCHAR(100), file_size VARCHAR(15), file_type VARCHAR(15), deleted_at DATETIME, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX claim_id_idx (claim_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE contact (id INT AUTO_INCREMENT, account_id INT, first_name VARCHAR(50) NOT NULL, last_name VARCHAR(50) NOT NULL, email VARCHAR(100), title VARCHAR(50), opt_in_email TINYINT(1) DEFAULT '1', opt_in_fax TINYINT(1) DEFAULT '0', opt_in_phone TINYINT(1) DEFAULT '1', blacklist TINYINT(1) DEFAULT '0', in_email_autocomplete TINYINT(1) DEFAULT '0', default_address_id INT, sf_guard_user_id INT, employee_id INT, quickbooks_listid VARCHAR(25), site_id VARCHAR(2) DEFAULT 'BD', campaign_id INT, is_repeat TINYINT(1), prefers_phone TINYINT(1), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX account_id_idx (account_id), INDEX campaign_id_idx (campaign_id), INDEX sf_guard_user_id_idx (sf_guard_user_id), INDEX employee_id_idx (employee_id), INDEX default_address_id_idx (default_address_id), INDEX site_id_idx (site_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE country (id VARCHAR(2), name VARCHAR(255) NOT NULL, iso_code_3 VARCHAR(3) NOT NULL UNIQUE, iso_num VARCHAR(3) NOT NULL UNIQUE, address_format VARCHAR(255), deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE email (id BIGINT AUTO_INCREMENT, from_contact_id INT, from_emp_profile_id INT, mime_message_id VARCHAR(50), subject VARCHAR(150) NOT NULL, headers TEXT, body_html TEXT NOT NULL, quote_id INT, template_id INT, is_read TINYINT(1), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX from_contact_id_idx (from_contact_id), INDEX from_emp_profile_id_idx (from_emp_profile_id), INDEX quote_id_idx (quote_id), INDEX template_id_idx (template_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE email_recipients (id BIGINT AUTO_INCREMENT, message_id BIGINT, type VARCHAR(5), recipient VARCHAR(200), INDEX email_recipients_type_idx (type), INDEX message_id_idx (message_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE email_rules (id INT AUTO_INCREMENT, name VARCHAR(50), action_type VARCHAR(255), account_id INT, email_to VARCHAR(255), email_cc VARCHAR(255), email_bcc VARCHAR(255), deleted_at DATETIME, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX account_id_idx (account_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE employee_profile (id INT AUTO_INCREMENT, contact_id INT, sf_guard_user_id INT, site_id VARCHAR(2), public_name VARCHAR(50), title VARCHAR(50), email VARCHAR(60), smtp_s VARCHAR(60), smtp_u VARCHAR(60), smtp_p VARCHAR(60), click2call VARCHAR(125), signature TEXT, phone_toll_free VARCHAR(20), phone_alt VARCHAR(20), deleted_at DATETIME, UNIQUE INDEX contact_site_idx (contact_id, site_id), INDEX contact_id_idx (contact_id), INDEX site_id_idx (site_id), INDEX sf_guard_user_id_idx (sf_guard_user_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE gallery (id INT AUTO_INCREMENT, parent_id INT, title VARCHAR(150), description VARCHAR(255), details VARCHAR(255), thumbnail VARCHAR(255), main_image VARCHAR(255), url_slug VARCHAR(150), sort_order SMALLINT, is_published TINYINT(1), deleted_at DATETIME, INDEX parent_id_idx (parent_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE gallery_image (id INT AUTO_INCREMENT, gallery_id INT, filename VARCHAR(100), caption VARCHAR(255), alt_text VARCHAR(150), INDEX gallery_id_idx (gallery_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE geo_zone (id INT AUTO_INCREMENT, name VARCHAR(32), description VARCHAR(150), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE glossary (id INT AUTO_INCREMENT, letter VARCHAR(1), word VARCHAR(150), definition TEXT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE inventory (id INT AUTO_INCREMENT, lot_no VARCHAR(25), warehouse_id INT, product_id INT, track_qty TINYINT(1), quantity DECIMAL(6, 2), status VARCHAR(255), status_detail VARCHAR(25), INDEX warehouse_id_idx (warehouse_id), INDEX product_id_idx (product_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE location_type (id TINYINT AUTO_INCREMENT, name VARCHAR(50), fq_id VARCHAR(10), list_order SMALLINT, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE mail_message (id BIGINT AUTO_INCREMENT, message LONGBLOB NOT NULL, priority BIGINT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE newsletter (id MEDIUMINT AUTO_INCREMENT, name VARCHAR(50), description VARCHAR(255), site_id VARCHAR(2), INDEX site_id_idx (site_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE newsletter_campaign (id BIGINT AUTO_INCREMENT, name VARCHAR(100), reference_code VARCHAR(50), site_id VARCHAR(2), newsletter_id MEDIUMINT, opens INT, clicks INT, sent INT, criteria VARCHAR(255), template_special_id INT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX newsletter_id_idx (newsletter_id), INDEX template_special_id_idx (template_special_id), INDEX site_id_idx (site_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE newsletter_campaign_subscriber (id BIGINT AUTO_INCREMENT, newsletter_campaign_id BIGINT, newsletter_subscriber_id BIGINT, INDEX newsletter_campaign_id_idx (newsletter_campaign_id), INDEX newsletter_subscriber_id_idx (newsletter_subscriber_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE newsletter_subscriber (id BIGINT AUTO_INCREMENT, contact_id INT, newsletter_id MEDIUMINT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX contact_id_idx (contact_id), INDEX newsletter_id_idx (newsletter_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE note (id BIGINT AUTO_INCREMENT, message TEXT, parent_type VARCHAR(20), parent_id INT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX note_parent_type_idx (parent_type), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE orders (id INT AUTO_INCREMENT, contact_id INT, quote_id INT, order_status_id TINYINT, ship_email VARCHAR(100), ship_address_id INT, bill_email VARCHAR(100), bill_address_id INT, note_dashboard VARCHAR(150), employee_id INT, site_id VARCHAR(2), campaign_id INT, quickbooks_listid VARCHAR(25), invoice_num VARCHAR(5), invoice_amt DECIMAL(14, 2), payment VARCHAR(255) DEFAULT 'Pending', balance_due_date DATE, signed_invoice TINYINT(1), signed_receipt TINYINT(1), thanked TINYINT(1), surveyed TINYINT(1), send_survey TINYINT(1) DEFAULT '1', unread TINYINT(1), payment_term_id TINYINT, payment_method_id TINYINT, commission_amt DECIMAL(6, 2), commission_pd TINYINT(1), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX contact_id_idx (contact_id), INDEX campaign_id_idx (campaign_id), INDEX quote_id_idx (quote_id), INDEX site_id_idx (site_id), INDEX order_status_id_idx (order_status_id), INDEX payment_term_id_idx (payment_term_id), INDEX payment_method_id_idx (payment_method_id), INDEX employee_id_idx (employee_id), INDEX ship_address_id_idx (ship_address_id), INDEX bill_address_id_idx (bill_address_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE order_document (id INT AUTO_INCREMENT, order_id INT, file_location VARCHAR(100) DEFAULT 'signed', file_name VARCHAR(100), file_size VARCHAR(15), file_type VARCHAR(15), document VARCHAR(255), source VARCHAR(255), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX order_id_idx (order_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE order_document_detail (id INT AUTO_INCREMENT, order_document_id INT, sender VARCHAR(100), recipient VARCHAR(150), recipientcc VARCHAR(150), date datetime, subject VARCHAR(255), headers TEXT, body_text TEXT, body_html TEXT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX order_document_id_idx (order_document_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE order_item (id INT AUTO_INCREMENT, order_shipment_id INT, product_id INT, quantity_bulk DECIMAL(6, 2), quantity DECIMAL(14, 2), price DECIMAL(10, 2), cost DECIMAL(10, 2), deleted_at DATETIME, INDEX order_shipment_id_idx (order_shipment_id), INDEX product_id_idx (product_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE order_shipment (id INT AUTO_INCREMENT, accountwarehouse_id INT, delivery_date DATE, customer_charge DECIMAL(10, 2), handling_fee DECIMAL(5, 2), our_cost DECIMAL(10, 2), ship_carrier_id INT, ship_method_id BIGINT, ship_weight DECIMAL(10, 2), ship_pallets TINYINT, ship_dim_l SMALLINT, ship_dim_w SMALLINT, ship_dim_h SMALLINT, fq_quoteid VARCHAR(14), fq_optionid VARCHAR(2), ship_to_alternate TINYINT(1), order_id INT, vendor_ref_no VARCHAR(15), po_no VARCHAR(6), release_no VARCHAR(25), tracking_no VARCHAR(25), bol_no VARCHAR(25), ship_brokered_carrier_id INT, pickup_date DATE, customer_notified TINYINT(1), dates_are_approx TINYINT(1), on_hold TINYINT(1), note VARCHAR(40), ship_ready_date DATE, ship_description VARCHAR(255), ship_cod TINYINT(1), ship_blind TINYINT(1), ship_call_ahead TINYINT(1) DEFAULT '1', need_box_truck TINYINT(1), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX ship_carrier_id_idx (ship_carrier_id), INDEX ship_method_id_idx (ship_method_id), INDEX accountwarehouse_id_idx (accountwarehouse_id), INDEX order_id_idx (order_id), INDEX ship_brokered_carrier_id_idx (ship_brokered_carrier_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE order_status (id TINYINT AUTO_INCREMENT, name VARCHAR(50), position BIGINT, deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE order_terms (id BIGINT AUTO_INCREMENT, term_id BIGINT, order_id INT, deleted_at DATETIME, INDEX term_id_idx (term_id), INDEX order_id_idx (order_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE order_transaction (id INT AUTO_INCREMENT, order_id INT, payment_method_id TINYINT, amount DECIMAL(14, 2), ip_address VARCHAR(16), result VARCHAR(75), result_code VARCHAR(4), result_subcode VARCHAR(4), avs_code VARCHAR(1), trans_num VARCHAR(20), authcode VARCHAR(15), trans_type VARCHAR(255), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX order_id_idx (order_id), INDEX payment_method_id_idx (payment_method_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE payment_method (id TINYINT AUTO_INCREMENT, name VARCHAR(50), quickbooks_id VARCHAR(25), deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE payment_term (id TINYINT AUTO_INCREMENT, name VARCHAR(50), quickbooks_id VARCHAR(25), deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE paypal_i_p_n (id INT AUTO_INCREMENT, first_name VARCHAR(75), last_name VARCHAR(75), email VARCHAR(100), address VARCHAR(150), city VARCHAR(50) NOT NULL, state VARCHAR(2) NOT NULL, postcode VARCHAR(20) NOT NULL, country_id VARCHAR(2) DEFAULT 'US' NOT NULL, is_shipped TINYINT(1) DEFAULT '0', options VARCHAR(255), item_number VARCHAR(50), item_name VARCHAR(150), txn_id VARCHAR(25), shipped_via VARCHAR(25), tracking_num VARCHAR(25), shipped_on DATE, deleted_at DATETIME, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, UNIQUE INDEX tracking_idx (first_name, last_name, postcode, tracking_num), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE phone (id BIGINT AUTO_INCREMENT, contact_id INT, number VARCHAR(20), type VARCHAR(255), deleted_at DATETIME, INDEX contact_id_idx (contact_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE product (id INT AUTO_INCREMENT, name VARCHAR(255) NOT NULL, name_invoice VARCHAR(255), name_po VARCHAR(255), attribute_set_id INT, quickbooks_listid VARCHAR(25), short_description TEXT, description TEXT, sku VARCHAR(25) NOT NULL, manu_sku VARCHAR(25), units VARCHAR(4), package_type VARCHAR(255), sold_by_package TINYINT(1) DEFAULT '1', weight_per_unit DECIMAL(8, 2), weight_per_package DECIMAL(10, 2), weight_per_pallet DECIMAL(12, 2), units_per_package DECIMAL(10, 2), units_per_pallet DECIMAL(10, 2), units_min_order INT, package_ship_height SMALLINT, package_ship_width SMALLINT, package_ship_length SMALLINT, pallet_ship_height SMALLINT, pallet_ship_width SMALLINT, pallet_ship_length SMALLINT, meta_title VARCHAR(150), meta_keywords VARCHAR(255), meta_description VARCHAR(255), account_id INT, product_line_id INT NOT NULL, price_full_retail DECIMAL(10, 2), cost DECIMAL(10, 2), tax_class_id TINYINT DEFAULT '1', image_thumb VARCHAR(255), image_primary VARCHAR(255), photogallery_id INT, freight_class VARCHAR(3), freight_nmfc VARCHAR(15), manage_inventory TINYINT(1) DEFAULT '0', times_viewed INT, times_quoted INT, product_url VARCHAR(255), url_slug VARCHAR(255), call_for_price TINYINT(1), samples_available TINYINT(1) DEFAULT '0', price_match TINYINT(1), lead_time VARCHAR(15), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX attribute_set_id_idx (attribute_set_id), INDEX account_id_idx (account_id), INDEX product_line_id_idx (product_line_id), INDEX tax_class_id_idx (tax_class_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE product_attribute (id INT AUTO_INCREMENT, name VARCHAR(100) NOT NULL, label VARCHAR(100), help VARCHAR(255), input_type VARCHAR(255), public TINYINT(1) DEFAULT '1', required TINYINT(1), searchable TINYINT(1), comparable TINYINT(1), layered_use TINYINT(1), list_order SMALLINT, position BIGINT, deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE product_attribute_option (id INT AUTO_INCREMENT, attribute_id INT, val VARCHAR(100), details TEXT, deleted_at DATETIME, INDEX attribute_id_idx (attribute_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE product_attribute_set_ship_method (id BIGINT AUTO_INCREMENT, attribute_set_id INT, ship_method_id BIGINT, deleted_at DATETIME, INDEX attribute_set_id_idx (attribute_set_id), INDEX ship_method_id_idx (ship_method_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE product_attribute_value (id INT AUTO_INCREMENT, product_id INT, attribute_id INT, val VARCHAR(150), deleted_at DATETIME, INDEX product_id_idx (product_id), INDEX attribute_id_idx (attribute_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE product_category (id INT AUTO_INCREMENT, name VARCHAR(150), url_slug VARCHAR(255) UNIQUE, subcategory_layout VARCHAR(255), thumbnail VARCHAR(255), short_description VARCHAR(255), long_description TEXT, page_title VARCHAR(100), meta_keywords VARCHAR(255), meta_desc VARCHAR(255), in_navigation TINYINT(1) DEFAULT '1', root_id BIGINT, lft INT, rgt INT, level SMALLINT, deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE product_category_product (product_id INT, productcategory_id INT, deleted_at DATETIME, PRIMARY KEY(product_id, productcategory_id)) ENGINE = INNODB;
CREATE TABLE product_cost (id INT AUTO_INCREMENT, product_id INT, method VARCHAR(255), min_qty DECIMAL(10, 2), max_qty DECIMAL(10, 2), price DECIMAL(10, 2), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX product_id_idx (product_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE product_line (id INT AUTO_INCREMENT, name VARCHAR(255), description TEXT, warranty TEXT, installation TEXT, account_id INT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX account_id_idx (account_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE product_price (id INT AUTO_INCREMENT, account_type_id VARCHAR(1), product_id INT, site_id VARCHAR(2), min_qty DECIMAL(10, 2), price DECIMAL(10, 2), special_price DECIMAL(10, 2), special_from_date DATE, special_to_date DATE, visible TINYINT(1), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX account_type_id_idx (account_type_id), INDEX product_id_idx (product_id), INDEX site_id_idx (site_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE quotes (id INT AUTO_INCREMENT, contact_id INT, bill_address_id INT, ship_address_id INT, installation_area VARCHAR(255), installation_subfloor VARCHAR(255), date_needed DATE, urgency VARCHAR(255), site_id VARCHAR(2), campaign_id INT, quote_status_id TINYINT, quote_quality_id TINYINT, rep_classification VARCHAR(255), notes_internal TEXT, notes_list VARCHAR(100), notes_from_user VARCHAR(255), employee_id INT, employee_previous_id INT, e_followup_on DATE, p_followup_on DATE, dont_follow_up_before DATE, unread TINYINT(1), installation_needed TINYINT(1), on_autopilot TINYINT(1), can_checkout TINYINT(1), receive_offers TINYINT(1), last_template_id INT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX campaign_id_idx (campaign_id), INDEX contact_id_idx (contact_id), INDEX site_id_idx (site_id), INDEX quote_status_id_idx (quote_status_id), INDEX quote_quality_id_idx (quote_quality_id), INDEX employee_id_idx (employee_id), INDEX employee_previous_id_idx (employee_previous_id), INDEX bill_address_id_idx (bill_address_id), INDEX ship_address_id_idx (ship_address_id), INDEX last_template_id_idx (last_template_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE quote_item (id INT AUTO_INCREMENT, quote_shipment_id INT, product_id INT, quantity_bulk DECIMAL(6, 2), quantity DECIMAL(14, 2), price DECIMAL(10, 2), cost DECIMAL(10, 2), deleted_at DATETIME, INDEX quote_shipment_id_idx (quote_shipment_id), INDEX product_id_idx (product_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE quote_quality (id TINYINT AUTO_INCREMENT, name VARCHAR(50), position BIGINT, deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE quote_sample (id INT AUTO_INCREMENT, quote_id INT, product_id INT, product_id_2 INT, tracking_no VARCHAR(25), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX quote_id_idx (quote_id), INDEX product_id_idx (product_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE quote_saved_search (id INT AUTO_INCREMENT, name VARCHAR(30), user_id INT, params VARCHAR(255), position BIGINT, INDEX user_id_idx (user_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE quote_shipment (id INT AUTO_INCREMENT, accountwarehouse_id INT, delivery_date DATE, customer_charge DECIMAL(10, 2), handling_fee DECIMAL(5, 2), our_cost DECIMAL(10, 2), ship_carrier_id INT, ship_method_id BIGINT, ship_weight DECIMAL(10, 2), ship_pallets TINYINT, ship_dim_l SMALLINT, ship_dim_w SMALLINT, ship_dim_h SMALLINT, fq_quoteid VARCHAR(14), fq_optionid VARCHAR(2), ship_to_alternate TINYINT(1), quote_id INT, transit_time SMALLINT, need_box_truck TINYINT(1), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX ship_carrier_id_idx (ship_carrier_id), INDEX ship_method_id_idx (ship_method_id), INDEX accountwarehouse_id_idx (accountwarehouse_id), INDEX quote_id_idx (quote_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE quote_status (id TINYINT AUTO_INCREMENT, name VARCHAR(50), position BIGINT, deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE ship_brokered_carrier (id INT AUTO_INCREMENT, name VARCHAR(50), scac VARCHAR(5), fq_id VARCHAR(5), url_primary VARCHAR(150), url_tracking VARCHAR(255), deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE ship_carrier (id INT AUTO_INCREMENT, name VARCHAR(50), type VARCHAR(255), url_primary VARCHAR(150), url_tracking VARCHAR(255), deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE ship_method (id BIGINT AUTO_INCREMENT, name VARCHAR(50), ship_carrier_id INT, enabled TINYINT(1) DEFAULT '1', INDEX ship_carrier_id_idx (ship_carrier_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE shipment (id INT AUTO_INCREMENT, accountwarehouse_id INT, delivery_date DATE, customer_charge DECIMAL(10, 2), handling_fee DECIMAL(5, 2), our_cost DECIMAL(10, 2), ship_carrier_id INT, ship_method_id BIGINT, ship_weight DECIMAL(10, 2), ship_pallets TINYINT, ship_dim_l SMALLINT, ship_dim_w SMALLINT, ship_dim_h SMALLINT, fq_quoteid VARCHAR(14), fq_optionid VARCHAR(2), ship_to_alternate TINYINT(1), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX ship_carrier_id_idx (ship_carrier_id), INDEX ship_method_id_idx (ship_method_id), INDEX accountwarehouse_id_idx (accountwarehouse_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE site (id VARCHAR(2) UNIQUE, name VARCHAR(255) NOT NULL, url VARCHAR(255) NOT NULL, catalog_root_id INT, deleted_at DATETIME, INDEX catalog_root_id_idx (catalog_root_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE special (id INT AUTO_INCREMENT, name VARCHAR(50), site_id VARCHAR(2), warehouse_id INT, product_id INT, quantity DECIMAL(10, 2), date_start datetime, date_end datetime, deleted_at DATETIME, INDEX warehouse_id_idx (warehouse_id), INDEX site_id_idx (site_id), PRIMARY KEY(id, product_id)) ENGINE = INNODB;
CREATE TABLE tax_class (id TINYINT AUTO_INCREMENT, name VARCHAR(255) NOT NULL, deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE template (id INT AUTO_INCREMENT, name VARCHAR(150), name_short VARCHAR(15), reference VARCHAR(50), version MEDIUMINT, email_subject VARCHAR(150), body TEXT, template_location VARCHAR(255), sequence TINYINT, wait_before_next INT, template_category_id INT, site_id VARCHAR(2), vars VARCHAR(255), is_public TINYINT(1), is_advanced TINYINT(1), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX template_category_id_idx (template_category_id), INDEX site_id_idx (site_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE template_category (id INT AUTO_INCREMENT, name VARCHAR(150), is_public TINYINT(1), root_id BIGINT, lft INT, rgt INT, level SMALLINT, position BIGINT, deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE template_special (id INT AUTO_INCREMENT, name VARCHAR(50), version MEDIUMINT, site_id VARCHAR(2), email_subject VARCHAR(150), body TEXT, date_start DATE, date_end DATE, template_special_category_id INT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX site_id_idx (site_id), INDEX template_special_category_id_idx (template_special_category_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE template_special_category (id INT AUTO_INCREMENT, name VARCHAR(50), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE term (id BIGINT AUTO_INCREMENT, name VARCHAR(50), description TEXT, quickbooks_listid VARCHAR(25), position BIGINT, deleted_at DATETIME, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE term_set (id BIGINT AUTO_INCREMENT, name VARCHAR(50), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE term_set_term (id BIGINT AUTO_INCREMENT, term_id BIGINT, term_set_id BIGINT, deleted_at DATETIME, INDEX term_set_id_idx (term_set_id), INDEX term_id_idx (term_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE testimonial (id BIGINT AUTO_INCREMENT, order_id INT, testimonial TEXT, deleted_at DATETIME, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX order_id_idx (order_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE testimonial_photo (id BIGINT AUTO_INCREMENT, testimonial_id BIGINT, file_name_thumb VARCHAR(100), file_name VARCHAR(100), file_size VARCHAR(15), file_type VARCHAR(15), INDEX testimonial_id_idx (testimonial_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE voicemail (id INT AUTO_INCREMENT, contact_id INT, employee_id INT, quote_id INT, phone_num VARCHAR(20), subject VARCHAR(100), body TEXT, file_location VARCHAR(150) DEFAULT 'voicemail', file_name VARCHAR(100), file_size VARCHAR(15), file_type VARCHAR(15) DEFAULT 'audio/mpeg', need_followup TINYINT(1) DEFAULT '1', unassigned TINYINT(1) DEFAULT '1', deleted_at DATETIME, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX contact_id_idx (contact_id), INDEX quote_id_idx (quote_id), INDEX employee_id_idx (employee_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE warehouse (id INT AUTO_INCREMENT, name VARCHAR(100) NOT NULL, nickname VARCHAR(50), address VARCHAR(100), address2 VARCHAR(100), city VARCHAR(50) NOT NULL, zone_id INT NOT NULL, postcode VARCHAR(20) NOT NULL, country_id VARCHAR(2) DEFAULT 'US' NOT NULL, contact VARCHAR(50), email VARCHAR(100), breaks_pallets TINYINT(1) DEFAULT '1', break_fee DECIMAL(6, 2), break_fee_notes VARCHAR(255), rush_fee DECIMAL(6, 2), pickup_after VARCHAR(20), pickup_before VARCHAR(20), phone VARCHAR(20), phone_alt VARCHAR(20), fax VARCHAR(20), fax_alt VARCHAR(20), customer_can_pickup TINYINT(1), appointment_required TINYINT(1), hr_notice_req VARCHAR(2), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, INDEX country_id_idx (country_id), INDEX zone_id_idx (zone_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE zone (id INT AUTO_INCREMENT, name VARCHAR(255) NOT NULL, code VARCHAR(32) NOT NULL, country_id VARCHAR(2) NOT NULL, deleted_at DATETIME, INDEX country_id_idx (country_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE zone_geo_zone (country_id VARCHAR(2), zone_id INT, geo_zone_id INT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, deleted_at DATETIME, PRIMARY KEY(country_id, zone_id, geo_zone_id)) ENGINE = INNODB;
CREATE TABLE sf_guard_group (id INT AUTO_INCREMENT, name VARCHAR(255) UNIQUE, description TEXT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE sf_guard_group_permission (group_id INT, permission_id INT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(group_id, permission_id)) ENGINE = INNODB;
CREATE TABLE sf_guard_permission (id INT AUTO_INCREMENT, name VARCHAR(255) UNIQUE, description TEXT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE sf_guard_remember_key (id INT AUTO_INCREMENT, user_id INT, remember_key VARCHAR(32), ip_address VARCHAR(50), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX user_id_idx (user_id), PRIMARY KEY(id, ip_address)) ENGINE = INNODB;
CREATE TABLE sf_guard_user (id INT AUTO_INCREMENT, username VARCHAR(128) NOT NULL UNIQUE, algorithm VARCHAR(128) DEFAULT 'sha1' NOT NULL, salt VARCHAR(128), password VARCHAR(128), is_active TINYINT(1) DEFAULT '1', is_super_admin TINYINT(1) DEFAULT '0', last_login DATETIME, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX is_active_idx_idx (is_active), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE sf_guard_user_group (user_id INT, group_id INT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(user_id, group_id)) ENGINE = INNODB;
CREATE TABLE sf_guard_user_permission (user_id INT, permission_id INT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(user_id, permission_id)) ENGINE = INNODB;
ALTER TABLE account ADD CONSTRAINT account_site_id_site_id FOREIGN KEY (site_id) REFERENCES site(id);
ALTER TABLE account ADD CONSTRAINT account_ship_zone_id_zone_id FOREIGN KEY (ship_zone_id) REFERENCES zone(id);
ALTER TABLE account ADD CONSTRAINT account_ship_country_id_country_id FOREIGN KEY (ship_country_id) REFERENCES country(id);
ALTER TABLE account ADD CONSTRAINT account_employee_id_sf_guard_user_id FOREIGN KEY (employee_id) REFERENCES sf_guard_user(id);
ALTER TABLE account ADD CONSTRAINT account_campaign_id_campaign_id FOREIGN KEY (campaign_id) REFERENCES campaign(id);
ALTER TABLE account ADD CONSTRAINT account_bill_zone_id_zone_id FOREIGN KEY (bill_zone_id) REFERENCES zone(id);
ALTER TABLE account ADD CONSTRAINT account_bill_country_id_country_id FOREIGN KEY (bill_country_id) REFERENCES country(id);
ALTER TABLE account ADD CONSTRAINT account_account_type_id_account_type_id FOREIGN KEY (account_type_id) REFERENCES account_type(id);
ALTER TABLE account_warehouse ADD CONSTRAINT account_warehouse_warehouse_id_warehouse_id FOREIGN KEY (warehouse_id) REFERENCES warehouse(id);
ALTER TABLE account_warehouse ADD CONSTRAINT account_warehouse_account_id_account_id FOREIGN KEY (account_id) REFERENCES account(id);
ALTER TABLE address ADD CONSTRAINT address_zone_id_zone_id FOREIGN KEY (zone_id) REFERENCES zone(id);
ALTER TABLE address ADD CONSTRAINT address_phone_id_phone_id FOREIGN KEY (phone_id) REFERENCES phone(id);
ALTER TABLE address ADD CONSTRAINT address_phone_alt_id_phone_id FOREIGN KEY (phone_alt_id) REFERENCES phone(id);
ALTER TABLE address ADD CONSTRAINT address_location_type_id_location_type_id FOREIGN KEY (location_type_id) REFERENCES location_type(id);
ALTER TABLE address ADD CONSTRAINT address_country_id_country_id FOREIGN KEY (country_id) REFERENCES country(id);
ALTER TABLE address ADD CONSTRAINT address_contact_id_contact_id FOREIGN KEY (contact_id) REFERENCES contact(id);
ALTER TABLE address_book ADD CONSTRAINT address_book_contact_id_contact_id FOREIGN KEY (contact_id) REFERENCES contact(id);
ALTER TABLE attribute_set_product_attribute ADD CONSTRAINT appi FOREIGN KEY (product_attribute_id) REFERENCES product_attribute(id);
ALTER TABLE attribute_set_product_attribute ADD CONSTRAINT aaai FOREIGN KEY (attribute_set_id) REFERENCES attribute_set(id);
ALTER TABLE claim ADD CONSTRAINT claim_order_shipment_id_order_shipment_id FOREIGN KEY (order_shipment_id) REFERENCES order_shipment(id);
ALTER TABLE claim_file ADD CONSTRAINT claim_file_claim_id_claim_id FOREIGN KEY (claim_id) REFERENCES claim(id);
ALTER TABLE contact ADD CONSTRAINT contact_site_id_site_id FOREIGN KEY (site_id) REFERENCES site(id);
ALTER TABLE contact ADD CONSTRAINT contact_sf_guard_user_id_sf_guard_user_id FOREIGN KEY (sf_guard_user_id) REFERENCES sf_guard_user(id) ON DELETE CASCADE;
ALTER TABLE contact ADD CONSTRAINT contact_employee_id_sf_guard_user_id FOREIGN KEY (employee_id) REFERENCES sf_guard_user(id);
ALTER TABLE contact ADD CONSTRAINT contact_default_address_id_address_id FOREIGN KEY (default_address_id) REFERENCES address(id);
ALTER TABLE contact ADD CONSTRAINT contact_campaign_id_campaign_id FOREIGN KEY (campaign_id) REFERENCES campaign(id);
ALTER TABLE contact ADD CONSTRAINT contact_account_id_account_id FOREIGN KEY (account_id) REFERENCES account(id);
ALTER TABLE email ADD CONSTRAINT email_template_id_template_id FOREIGN KEY (template_id) REFERENCES template(id);
ALTER TABLE email ADD CONSTRAINT email_quote_id_quotes_id FOREIGN KEY (quote_id) REFERENCES quotes(id);
ALTER TABLE email ADD CONSTRAINT email_from_emp_profile_id_employee_profile_id FOREIGN KEY (from_emp_profile_id) REFERENCES employee_profile(id);
ALTER TABLE email ADD CONSTRAINT email_from_contact_id_contact_id FOREIGN KEY (from_contact_id) REFERENCES contact(id);
ALTER TABLE email_recipients ADD CONSTRAINT email_recipients_message_id_email_recipients_id FOREIGN KEY (message_id) REFERENCES email_recipients(id);
ALTER TABLE email_rules ADD CONSTRAINT email_rules_account_id_account_id FOREIGN KEY (account_id) REFERENCES account(id);
ALTER TABLE employee_profile ADD CONSTRAINT employee_profile_site_id_site_id FOREIGN KEY (site_id) REFERENCES site(id);
ALTER TABLE employee_profile ADD CONSTRAINT employee_profile_sf_guard_user_id_sf_guard_user_id FOREIGN KEY (sf_guard_user_id) REFERENCES sf_guard_user(id);
ALTER TABLE employee_profile ADD CONSTRAINT employee_profile_contact_id_contact_id FOREIGN KEY (contact_id) REFERENCES contact(id);
ALTER TABLE gallery ADD CONSTRAINT gallery_parent_id_gallery_id FOREIGN KEY (parent_id) REFERENCES gallery(id);
ALTER TABLE gallery_image ADD CONSTRAINT gallery_image_gallery_id_gallery_id FOREIGN KEY (gallery_id) REFERENCES gallery(id);
ALTER TABLE inventory ADD CONSTRAINT inventory_warehouse_id_warehouse_id FOREIGN KEY (warehouse_id) REFERENCES warehouse(id);
ALTER TABLE inventory ADD CONSTRAINT inventory_product_id_product_id FOREIGN KEY (product_id) REFERENCES product(id);
ALTER TABLE newsletter ADD CONSTRAINT newsletter_site_id_site_id FOREIGN KEY (site_id) REFERENCES site(id);
ALTER TABLE newsletter_campaign ADD CONSTRAINT newsletter_campaign_template_special_id_template_special_id FOREIGN KEY (template_special_id) REFERENCES template_special(id);
ALTER TABLE newsletter_campaign ADD CONSTRAINT newsletter_campaign_site_id_site_id FOREIGN KEY (site_id) REFERENCES site(id);
ALTER TABLE newsletter_campaign ADD CONSTRAINT newsletter_campaign_newsletter_id_newsletter_id FOREIGN KEY (newsletter_id) REFERENCES newsletter(id);
ALTER TABLE newsletter_campaign_subscriber ADD CONSTRAINT nnni_1 FOREIGN KEY (newsletter_subscriber_id) REFERENCES newsletter_campaign(id);
ALTER TABLE newsletter_campaign_subscriber ADD CONSTRAINT nnni FOREIGN KEY (newsletter_campaign_id) REFERENCES newsletter_subscriber(id);
ALTER TABLE newsletter_subscriber ADD CONSTRAINT newsletter_subscriber_newsletter_id_newsletter_id FOREIGN KEY (newsletter_id) REFERENCES newsletter(id);
ALTER TABLE newsletter_subscriber ADD CONSTRAINT newsletter_subscriber_contact_id_contact_id FOREIGN KEY (contact_id) REFERENCES contact(id);
ALTER TABLE orders ADD CONSTRAINT orders_site_id_site_id FOREIGN KEY (site_id) REFERENCES site(id);
ALTER TABLE orders ADD CONSTRAINT orders_ship_address_id_address_id FOREIGN KEY (ship_address_id) REFERENCES address(id);
ALTER TABLE orders ADD CONSTRAINT orders_quote_id_quotes_id FOREIGN KEY (quote_id) REFERENCES quotes(id);
ALTER TABLE orders ADD CONSTRAINT orders_payment_term_id_payment_term_id FOREIGN KEY (payment_term_id) REFERENCES payment_term(id);
ALTER TABLE orders ADD CONSTRAINT orders_payment_method_id_payment_method_id FOREIGN KEY (payment_method_id) REFERENCES payment_method(id);
ALTER TABLE orders ADD CONSTRAINT orders_order_status_id_order_status_id FOREIGN KEY (order_status_id) REFERENCES order_status(id);
ALTER TABLE orders ADD CONSTRAINT orders_employee_id_sf_guard_user_id FOREIGN KEY (employee_id) REFERENCES sf_guard_user(id);
ALTER TABLE orders ADD CONSTRAINT orders_contact_id_contact_id FOREIGN KEY (contact_id) REFERENCES contact(id);
ALTER TABLE orders ADD CONSTRAINT orders_campaign_id_campaign_id FOREIGN KEY (campaign_id) REFERENCES campaign(id);
ALTER TABLE orders ADD CONSTRAINT orders_bill_address_id_address_id FOREIGN KEY (bill_address_id) REFERENCES address(id);
ALTER TABLE order_document ADD CONSTRAINT order_document_order_id_orders_id FOREIGN KEY (order_id) REFERENCES orders(id);
ALTER TABLE order_document_detail ADD CONSTRAINT order_document_detail_order_document_id_order_document_id FOREIGN KEY (order_document_id) REFERENCES order_document(id);
ALTER TABLE order_item ADD CONSTRAINT order_item_product_id_product_id FOREIGN KEY (product_id) REFERENCES product(id);
ALTER TABLE order_item ADD CONSTRAINT order_item_order_shipment_id_order_shipment_id FOREIGN KEY (order_shipment_id) REFERENCES order_shipment(id);
ALTER TABLE order_shipment ADD CONSTRAINT order_shipment_ship_method_id_ship_method_id FOREIGN KEY (ship_method_id) REFERENCES ship_method(id);
ALTER TABLE order_shipment ADD CONSTRAINT order_shipment_ship_carrier_id_ship_carrier_id FOREIGN KEY (ship_carrier_id) REFERENCES ship_carrier(id);
ALTER TABLE order_shipment ADD CONSTRAINT order_shipment_ship_brokered_carrier_id_ship_brokered_carrier_id FOREIGN KEY (ship_brokered_carrier_id) REFERENCES ship_brokered_carrier(id);
ALTER TABLE order_shipment ADD CONSTRAINT order_shipment_order_id_orders_id FOREIGN KEY (order_id) REFERENCES orders(id);
ALTER TABLE order_shipment ADD CONSTRAINT order_shipment_accountwarehouse_id_account_warehouse_id FOREIGN KEY (accountwarehouse_id) REFERENCES account_warehouse(id);
ALTER TABLE order_terms ADD CONSTRAINT order_terms_term_id_term_id FOREIGN KEY (term_id) REFERENCES term(id);
ALTER TABLE order_terms ADD CONSTRAINT order_terms_order_id_orders_id FOREIGN KEY (order_id) REFERENCES orders(id);
ALTER TABLE order_transaction ADD CONSTRAINT order_transaction_payment_method_id_payment_method_id FOREIGN KEY (payment_method_id) REFERENCES payment_method(id);
ALTER TABLE order_transaction ADD CONSTRAINT order_transaction_order_id_orders_id FOREIGN KEY (order_id) REFERENCES orders(id);
ALTER TABLE phone ADD CONSTRAINT phone_contact_id_contact_id FOREIGN KEY (contact_id) REFERENCES contact(id);
ALTER TABLE product ADD CONSTRAINT product_tax_class_id_tax_class_id FOREIGN KEY (tax_class_id) REFERENCES tax_class(id);
ALTER TABLE product ADD CONSTRAINT product_product_line_id_product_line_id FOREIGN KEY (product_line_id) REFERENCES product_line(id);
ALTER TABLE product ADD CONSTRAINT product_attribute_set_id_attribute_set_id FOREIGN KEY (attribute_set_id) REFERENCES attribute_set(id);
ALTER TABLE product ADD CONSTRAINT product_account_id_account_id FOREIGN KEY (account_id) REFERENCES account(id);
ALTER TABLE product_attribute_option ADD CONSTRAINT product_attribute_option_attribute_id_product_attribute_id FOREIGN KEY (attribute_id) REFERENCES product_attribute(id);
ALTER TABLE product_attribute_set_ship_method ADD CONSTRAINT product_attribute_set_ship_method_ship_method_id_ship_method_id FOREIGN KEY (ship_method_id) REFERENCES ship_method(id);
ALTER TABLE product_attribute_set_ship_method ADD CONSTRAINT paai FOREIGN KEY (attribute_set_id) REFERENCES attribute_set(id);
ALTER TABLE product_attribute_value ADD CONSTRAINT product_attribute_value_product_id_product_id FOREIGN KEY (product_id) REFERENCES product(id);
ALTER TABLE product_attribute_value ADD CONSTRAINT product_attribute_value_attribute_id_product_attribute_id FOREIGN KEY (attribute_id) REFERENCES product_attribute(id);
ALTER TABLE product_category_product ADD CONSTRAINT product_category_product_productcategory_id_product_category_id FOREIGN KEY (productcategory_id) REFERENCES product_category(id);
ALTER TABLE product_category_product ADD CONSTRAINT product_category_product_product_id_product_id FOREIGN KEY (product_id) REFERENCES product(id);
ALTER TABLE product_cost ADD CONSTRAINT product_cost_product_id_product_id FOREIGN KEY (product_id) REFERENCES product(id);
ALTER TABLE product_line ADD CONSTRAINT product_line_account_id_account_id FOREIGN KEY (account_id) REFERENCES account(id);
ALTER TABLE product_price ADD CONSTRAINT product_price_site_id_site_id FOREIGN KEY (site_id) REFERENCES site(id);
ALTER TABLE product_price ADD CONSTRAINT product_price_product_id_product_id FOREIGN KEY (product_id) REFERENCES product(id);
ALTER TABLE product_price ADD CONSTRAINT product_price_account_type_id_account_type_id FOREIGN KEY (account_type_id) REFERENCES account_type(id);
ALTER TABLE quotes ADD CONSTRAINT quotes_site_id_site_id FOREIGN KEY (site_id) REFERENCES site(id);
ALTER TABLE quotes ADD CONSTRAINT quotes_ship_address_id_address_id FOREIGN KEY (ship_address_id) REFERENCES address(id);
ALTER TABLE quotes ADD CONSTRAINT quotes_quote_status_id_quote_status_id FOREIGN KEY (quote_status_id) REFERENCES quote_status(id);
ALTER TABLE quotes ADD CONSTRAINT quotes_quote_quality_id_quote_quality_id FOREIGN KEY (quote_quality_id) REFERENCES quote_quality(id);
ALTER TABLE quotes ADD CONSTRAINT quotes_last_template_id_template_id FOREIGN KEY (last_template_id) REFERENCES template(id);
ALTER TABLE quotes ADD CONSTRAINT quotes_employee_previous_id_sf_guard_user_id FOREIGN KEY (employee_previous_id) REFERENCES sf_guard_user(id);
ALTER TABLE quotes ADD CONSTRAINT quotes_employee_id_sf_guard_user_id FOREIGN KEY (employee_id) REFERENCES sf_guard_user(id);
ALTER TABLE quotes ADD CONSTRAINT quotes_contact_id_contact_id FOREIGN KEY (contact_id) REFERENCES contact(id);
ALTER TABLE quotes ADD CONSTRAINT quotes_campaign_id_campaign_id FOREIGN KEY (campaign_id) REFERENCES campaign(id);
ALTER TABLE quotes ADD CONSTRAINT quotes_bill_address_id_address_id FOREIGN KEY (bill_address_id) REFERENCES address(id);
ALTER TABLE quote_item ADD CONSTRAINT quote_item_quote_shipment_id_quote_shipment_id FOREIGN KEY (quote_shipment_id) REFERENCES quote_shipment(id);
ALTER TABLE quote_item ADD CONSTRAINT quote_item_product_id_product_id FOREIGN KEY (product_id) REFERENCES product(id);
ALTER TABLE quote_sample ADD CONSTRAINT quote_sample_quote_id_quotes_id FOREIGN KEY (quote_id) REFERENCES quotes(id);
ALTER TABLE quote_sample ADD CONSTRAINT quote_sample_product_id_product_id FOREIGN KEY (product_id) REFERENCES product(id);
ALTER TABLE quote_saved_search ADD CONSTRAINT quote_saved_search_user_id_sf_guard_user_id FOREIGN KEY (user_id) REFERENCES sf_guard_user(id);
ALTER TABLE quote_shipment ADD CONSTRAINT quote_shipment_ship_method_id_ship_method_id FOREIGN KEY (ship_method_id) REFERENCES ship_method(id);
ALTER TABLE quote_shipment ADD CONSTRAINT quote_shipment_ship_carrier_id_ship_carrier_id FOREIGN KEY (ship_carrier_id) REFERENCES ship_carrier(id);
ALTER TABLE quote_shipment ADD CONSTRAINT quote_shipment_quote_id_quotes_id FOREIGN KEY (quote_id) REFERENCES quotes(id);
ALTER TABLE quote_shipment ADD CONSTRAINT quote_shipment_accountwarehouse_id_account_warehouse_id FOREIGN KEY (accountwarehouse_id) REFERENCES account_warehouse(id);
ALTER TABLE ship_method ADD CONSTRAINT ship_method_ship_carrier_id_ship_carrier_id FOREIGN KEY (ship_carrier_id) REFERENCES ship_carrier(id);
ALTER TABLE shipment ADD CONSTRAINT shipment_ship_method_id_ship_method_id FOREIGN KEY (ship_method_id) REFERENCES ship_method(id);
ALTER TABLE shipment ADD CONSTRAINT shipment_ship_carrier_id_ship_carrier_id FOREIGN KEY (ship_carrier_id) REFERENCES ship_carrier(id);
ALTER TABLE shipment ADD CONSTRAINT shipment_accountwarehouse_id_account_warehouse_id FOREIGN KEY (accountwarehouse_id) REFERENCES account_warehouse(id);
ALTER TABLE site ADD CONSTRAINT site_catalog_root_id_product_category_id FOREIGN KEY (catalog_root_id) REFERENCES product_category(id);
ALTER TABLE special ADD CONSTRAINT special_warehouse_id_warehouse_id FOREIGN KEY (warehouse_id) REFERENCES warehouse(id);
ALTER TABLE special ADD CONSTRAINT special_site_id_site_id FOREIGN KEY (site_id) REFERENCES site(id);
ALTER TABLE special ADD CONSTRAINT special_product_id_product_id FOREIGN KEY (product_id) REFERENCES product(id);
ALTER TABLE template ADD CONSTRAINT template_template_category_id_template_category_id FOREIGN KEY (template_category_id) REFERENCES template_category(id);
ALTER TABLE template ADD CONSTRAINT template_site_id_site_id FOREIGN KEY (site_id) REFERENCES site(id);
ALTER TABLE template_special ADD CONSTRAINT ttti FOREIGN KEY (template_special_category_id) REFERENCES template_special_category(id);
ALTER TABLE template_special ADD CONSTRAINT template_special_site_id_site_id FOREIGN KEY (site_id) REFERENCES site(id);
ALTER TABLE term_set_term ADD CONSTRAINT term_set_term_term_set_id_term_set_id FOREIGN KEY (term_set_id) REFERENCES term_set(id);
ALTER TABLE term_set_term ADD CONSTRAINT term_set_term_term_id_term_id FOREIGN KEY (term_id) REFERENCES term(id);
ALTER TABLE testimonial ADD CONSTRAINT testimonial_order_id_orders_id FOREIGN KEY (order_id) REFERENCES orders(id);
ALTER TABLE testimonial_photo ADD CONSTRAINT testimonial_photo_testimonial_id_testimonial_id FOREIGN KEY (testimonial_id) REFERENCES testimonial(id);
ALTER TABLE voicemail ADD CONSTRAINT voicemail_quote_id_quotes_id FOREIGN KEY (quote_id) REFERENCES quotes(id);
ALTER TABLE voicemail ADD CONSTRAINT voicemail_employee_id_sf_guard_user_id FOREIGN KEY (employee_id) REFERENCES sf_guard_user(id);
ALTER TABLE voicemail ADD CONSTRAINT voicemail_contact_id_contact_id FOREIGN KEY (contact_id) REFERENCES contact(id);
ALTER TABLE warehouse ADD CONSTRAINT warehouse_zone_id_zone_id FOREIGN KEY (zone_id) REFERENCES zone(id);
ALTER TABLE warehouse ADD CONSTRAINT warehouse_country_id_country_id FOREIGN KEY (country_id) REFERENCES country(id);
ALTER TABLE zone ADD CONSTRAINT zone_country_id_country_id FOREIGN KEY (country_id) REFERENCES country(id);
ALTER TABLE zone_geo_zone ADD CONSTRAINT zone_geo_zone_zone_id_zone_id FOREIGN KEY (zone_id) REFERENCES zone(id);
ALTER TABLE zone_geo_zone ADD CONSTRAINT zone_geo_zone_geo_zone_id_geo_zone_id FOREIGN KEY (geo_zone_id) REFERENCES geo_zone(id);
ALTER TABLE zone_geo_zone ADD CONSTRAINT zone_geo_zone_country_id_country_id FOREIGN KEY (country_id) REFERENCES country(id);
ALTER TABLE sf_guard_group_permission ADD CONSTRAINT sf_guard_group_permission_permission_id_sf_guard_permission_id FOREIGN KEY (permission_id) REFERENCES sf_guard_permission(id) ON DELETE CASCADE;
ALTER TABLE sf_guard_group_permission ADD CONSTRAINT sf_guard_group_permission_group_id_sf_guard_group_id FOREIGN KEY (group_id) REFERENCES sf_guard_group(id) ON DELETE CASCADE;
ALTER TABLE sf_guard_remember_key ADD CONSTRAINT sf_guard_remember_key_user_id_sf_guard_user_id FOREIGN KEY (user_id) REFERENCES sf_guard_user(id) ON DELETE CASCADE;
ALTER TABLE sf_guard_user_group ADD CONSTRAINT sf_guard_user_group_user_id_sf_guard_user_id FOREIGN KEY (user_id) REFERENCES sf_guard_user(id) ON DELETE CASCADE;
ALTER TABLE sf_guard_user_group ADD CONSTRAINT sf_guard_user_group_group_id_sf_guard_group_id FOREIGN KEY (group_id) REFERENCES sf_guard_group(id) ON DELETE CASCADE;
ALTER TABLE sf_guard_user_permission ADD CONSTRAINT sf_guard_user_permission_user_id_sf_guard_user_id FOREIGN KEY (user_id) REFERENCES sf_guard_user(id) ON DELETE CASCADE;
ALTER TABLE sf_guard_user_permission ADD CONSTRAINT sf_guard_user_permission_permission_id_sf_guard_permission_id FOREIGN KEY (permission_id) REFERENCES sf_guard_permission(id) ON DELETE CASCADE;
CREATE TABLE email_recipients (id BIGINT AUTO_INCREMENT, message_id BIGINT, type VARCHAR(5), recipient VARCHAR(200), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE account (account_id INT AUTO_INCREMENT, account_type_id CHAR(1) DEFAULT '' NOT NULL, company_name VARCHAR(75) DEFAULT '' NOT NULL, phone_fax VARCHAR(25) DEFAULT '' NOT NULL, phone_office VARCHAR(25) DEFAULT '' NOT NULL, phone_alt VARCHAR(25) DEFAULT '' NOT NULL, website VARCHAR(75), email1 VARCHAR(50) DEFAULT '' NOT NULL, email2 VARCHAR(50) DEFAULT '' NOT NULL, no_employees INT, offers_install TINYINT, locations INT, default_bill_location_id INT, default_ship_location_id INT, annual_revenue VARCHAR(9), description TEXT, source VARCHAR(50), date_created DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL, date_modified DATETIME, restrict_level TINYINT DEFAULT '0' NOT NULL, authorized TINYINT DEFAULT '0' NOT NULL, is_active TINYINT DEFAULT '1' NOT NULL, employee_id VARCHAR(4) DEFAULT '' NOT NULL, quickbooks_listid VARCHAR(50) DEFAULT '' NOT NULL, install_price VARCHAR(5) NOT NULL, INDEX employee_id_idx (employee_id), PRIMARY KEY(account_id)) ENGINE = INNODB;
CREATE TABLE address (address_id INT AUTO_INCREMENT, type VARCHAR(1) DEFAULT 'B' NOT NULL, reference_name VARCHAR(50), address VARCHAR(80), address2 VARCHAR(50), city VARCHAR(60) DEFAULT '' NOT NULL, state CHAR(2) DEFAULT '' NOT NULL, zipcode INT DEFAULT '0' NOT NULL, is_active TINYINT DEFAULT '1' NOT NULL, contact_id INT DEFAULT '0' NOT NULL, PRIMARY KEY(address_id)) ENGINE = INNODB;
CREATE TABLE contact (contact_id INT AUTO_INCREMENT, account_id INT DEFAULT '0' NOT NULL, email VARCHAR(50) DEFAULT '' NOT NULL, password VARCHAR(60) DEFAULT '' NOT NULL, first_name VARCHAR(50) DEFAULT '' NOT NULL, last_name VARCHAR(50) DEFAULT '' NOT NULL, greeting VARCHAR(4), title VARCHAR(50), department VARCHAR(50), birthdate DATE, preferred_contact VARCHAR(17) DEFAULT '' NOT NULL, default_address INT, opt_in_email TINYINT DEFAULT '1' NOT NULL, opt_in_fax TINYINT DEFAULT '1' NOT NULL, opt_in_phone TINYINT DEFAULT '1' NOT NULL, opt_in_mail TINYINT DEFAULT '1' NOT NULL, phone_office VARCHAR(25) DEFAULT '' NOT NULL, phone_home VARCHAR(25) DEFAULT '' NOT NULL, phone_mobile VARCHAR(25) DEFAULT '' NOT NULL, fax VARCHAR(25) DEFAULT '' NOT NULL, email2 VARCHAR(50) DEFAULT '' NOT NULL, assistant_name VARCHAR(100), assistant_phone VARCHAR(15), is_main_contact TINYINT DEFAULT '0' NOT NULL, date_created DATETIME, date_modified DATETIME NOT NULL, date_last_login DATETIME, authorized TINYINT DEFAULT '0' NOT NULL, is_active TINYINT DEFAULT '1' NOT NULL, modify_acct_info TINYINT DEFAULT '0' NOT NULL, employee_id VARCHAR(4) DEFAULT '' NOT NULL, quickbooks_listid VARCHAR(25) NOT NULL, is_repeat TINYINT DEFAULT '0' NOT NULL, temp_mailchimped TINYINT NOT NULL, INDEX account_id_idx (account_id), INDEX default_address_idx (default_address), INDEX employee_id_idx (employee_id), PRIMARY KEY(contact_id)) ENGINE = INNODB;
CREATE TABLE employee (employee_id VARCHAR(4), access_level INT, username VARCHAR(15) DEFAULT '' NOT NULL, password VARCHAR(60) DEFAULT '' NOT NULL, greeting VARCHAR(4), first_name VARCHAR(50) DEFAULT '' NOT NULL, last_name VARCHAR(50) DEFAULT '' NOT NULL, title VARCHAR(50), department VARCHAR(50), email_bd VARCHAR(60) DEFAULT '' NOT NULL, email_home VARCHAR(60) DEFAULT '' NOT NULL, signature_bd TEXT, phone_office VARCHAR(25), phone_home VARCHAR(25), phone_mobile VARCHAR(25), extension VARCHAR(5) NOT NULL, c2c VARCHAR(255) NOT NULL, fax VARCHAR(25), address VARCHAR(150), address2 VARCHAR(100), city VARCHAR(60) DEFAULT '' NOT NULL, state CHAR(2) DEFAULT '' NOT NULL, zipcode INT DEFAULT '0' NOT NULL, is_active TINYINT DEFAULT '1' NOT NULL, quickbooks_listid VARCHAR(20) NOT NULL, PRIMARY KEY(employee_id)) ENGINE = INNODB;
CREATE TABLE orders (order_id INT AUTO_INCREMENT, quote_id VARCHAR(35) NOT NULL, date_created DATETIME, date_modified DATETIME, source VARCHAR(20), payment_terms VARCHAR(50), ship_company VARCHAR(150), ship_first VARCHAR(50) DEFAULT '' NOT NULL, ship_last VARCHAR(50) DEFAULT '' NOT NULL, ship_email VARCHAR(60), ship_addr VARCHAR(80), ship_addr2 VARCHAR(50), ship_city VARCHAR(60), ship_state CHAR(2), ship_zipcode VARCHAR(5), ship_req_date DATE NOT NULL, ship_req_details VARCHAR(20), ship_phone VARCHAR(20), ship_phone_alt VARCHAR(20), ship_type VARCHAR(15) NOT NULL, bol VARCHAR(25) NOT NULL, pro VARCHAR(25) NOT NULL, bill_company VARCHAR(150), bill_first VARCHAR(50) DEFAULT '' NOT NULL, bill_last VARCHAR(50) DEFAULT '' NOT NULL, bill_email VARCHAR(60) DEFAULT '' NOT NULL, bill_addr VARCHAR(80), bill_addr2 VARCHAR(50), bill_city VARCHAR(60), bill_state CHAR(2), bill_zipcode VARCHAR(5), bill_phone VARCHAR(20), installation_needed TINYINT DEFAULT '0', status_order_id INT, status_payment_id INT, last_msg_by VARCHAR(4), user_comments TEXT, is_active TINYINT DEFAULT '1', contact_id INT, employee_id VARCHAR(4), company_handling CHAR(3) DEFAULT 'BD', inv_num VARCHAR(8), inv_amt FLOAT(9, 2) DEFAULT 0.00, quickbooks_listid VARCHAR(50), quickbooks_txnid VARCHAR(25), quickbooks_editsequence VARCHAR(25), quickbooks_po_ref VARCHAR(25), status_signed_inv TINYINT DEFAULT '0', status_signed_receipt TINYINT DEFAULT '0', INDEX inv_num_idx (inv_num), INDEX employee_id_idx (employee_id), PRIMARY KEY(order_id)) ENGINE = INNODB;
CREATE TABLE quote (quote_id VARCHAR(35), date_created DATETIME, date_modified DATETIME, date_needed DATE DEFAULT '0000-00-00' NOT NULL, urgency VARCHAR(1) DEFAULT '2', source VARCHAR(20), payment_terms VARCHAR(50), reference_name VARCHAR(50) DEFAULT '' NOT NULL, preferred_contact VARCHAR(30) DEFAULT '' NOT NULL, ship_first VARCHAR(50) DEFAULT '' NOT NULL, ship_last VARCHAR(50) DEFAULT '' NOT NULL, ship_email VARCHAR(60) DEFAULT '' NOT NULL, ship_addr VARCHAR(80), ship_addr2 VARCHAR(50), ship_city VARCHAR(60), ship_state CHAR(2), ship_zipcode VARCHAR(5), ship_country CHAR(2) NOT NULL, ship_request_deliv VARCHAR(20), ship_phone VARCHAR(20), ship_phone_alt VARCHAR(20), ship_type VARCHAR(15) NOT NULL, bill_first VARCHAR(50) DEFAULT '' NOT NULL, bill_last VARCHAR(50) DEFAULT '' NOT NULL, bill_email VARCHAR(60) DEFAULT '' NOT NULL, bill_addr VARCHAR(80), bill_addr2 VARCHAR(50), bill_city VARCHAR(60), bill_state CHAR(2), bill_zipcode VARCHAR(5), install_area VARCHAR(11), install_subfloor VARCHAR(8), installation_needed TINYINT DEFAULT '0', status_id INT, quote_stage VARCHAR(25) NOT NULL, last_msg_by VARCHAR(4), rep_class_id CHAR(3) DEFAULT '' NOT NULL, last_template VARCHAR(50), last_offer VARCHAR(50), user_comments TEXT, is_active TINYINT DEFAULT '1', contact_id INT DEFAULT '0' NOT NULL, employee_id VARCHAR(4) DEFAULT '' NOT NULL, employee_id_prev VARCHAR(4) DEFAULT '' NOT NULL, company_handling CHAR(3) DEFAULT 'BD' NOT NULL, note VARCHAR(75) DEFAULT '' NOT NULL, last_followup VARCHAR(25) DEFAULT '' NOT NULL, followup_on DATE NOT NULL, mailchimped TINYINT(1), customer_cancelled TINYINT(1), utm_source VARCHAR(35), utm_medium VARCHAR(35), utm_term VARCHAR(35), utm_content VARCHAR(35), utm_campaign VARCHAR(35), INDEX contact_id_idx (contact_id), INDEX employee_id_idx (employee_id), PRIMARY KEY(quote_id)) ENGINE = INNODB;
CREATE TABLE temp_acc (id INT AUTO_INCREMENT, species VARCHAR(50), for_floor_height VARCHAR(10), finish VARCHAR(25), finish_notes VARCHAR(50), manu_match VARCHAR(25), temp_acc_profile_id TINYINT, moi_sku VARCHAR(20), quickbooks_listid VARCHAR(30), quickbooks_parent VARCHAR(20), price DECIMAL(6, 2), INDEX quickbooks_listid_idx (quickbooks_listid), INDEX temp_acc_profile_id_idx (temp_acc_profile_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE temp_acc_orders (id INT AUTO_INCREMENT, order_id INT, temp_acc_id INT, qty INT, INDEX temp_acc_id_idx (temp_acc_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE temp_acc_profile (id TINYINT, thickness VARCHAR(8), width VARCHAR(8), length VARCHAR(8), type VARCHAR(30), image_url TEXT, description VARCHAR(75), qb_name_part VARCHAR(20), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE temp_qb_po (id INT AUTO_INCREMENT, quickbooks_listid VARCHAR(25), po_num VARCHAR(10), inv_num VARCHAR(10), type CHAR(4), ordered TINYINT(1) DEFAULT '0', INDEX inv_num_idx (inv_num), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE temp_qb_po_line (id INT AUTO_INCREMENT, qb_inv_num VARCHAR(10) NOT NULL, qb_prod_id VARCHAR(25) NOT NULL, qb_po_listid VARCHAR(25) NOT NULL, qty DECIMAL(10, 2) NOT NULL, description VARCHAR(255) NOT NULL, type CHAR(4) NOT NULL, INDEX qb_inv_num_idx (qb_inv_num), INDEX qb_prod_id_idx (qb_prod_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE temp_qb_prod (id INT AUTO_INCREMENT, qb_listid VARCHAR(50) NOT NULL, description VARCHAR(255), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE temp_qb_repsales (timeperiod DATE, name VARCHAR(25), amount DECIMAL(9, 2), PRIMARY KEY(timeperiod, name)) ENGINE = INNODB;
ALTER TABLE account ADD CONSTRAINT account_employee_id_employee_employee_id FOREIGN KEY (employee_id) REFERENCES employee(employee_id);
ALTER TABLE contact ADD CONSTRAINT contact_employee_id_employee_employee_id FOREIGN KEY (employee_id) REFERENCES employee(employee_id);
ALTER TABLE contact ADD CONSTRAINT contact_default_address_address_address_id FOREIGN KEY (default_address) REFERENCES address(address_id);
ALTER TABLE contact ADD CONSTRAINT contact_account_id_account_account_id FOREIGN KEY (account_id) REFERENCES account(account_id);
ALTER TABLE orders ADD CONSTRAINT orders_employee_id_employee_employee_id FOREIGN KEY (employee_id) REFERENCES employee(employee_id);
ALTER TABLE quote ADD CONSTRAINT quote_employee_id_employee_employee_id FOREIGN KEY (employee_id) REFERENCES employee(employee_id);
ALTER TABLE quote ADD CONSTRAINT quote_contact_id_contact_contact_id FOREIGN KEY (contact_id) REFERENCES contact(contact_id);
ALTER TABLE temp_acc ADD CONSTRAINT temp_acc_temp_acc_profile_id_temp_acc_profile_id FOREIGN KEY (temp_acc_profile_id) REFERENCES temp_acc_profile(id);
ALTER TABLE temp_acc_orders ADD CONSTRAINT temp_acc_orders_temp_acc_id_temp_acc_id FOREIGN KEY (temp_acc_id) REFERENCES temp_acc(id);
ALTER TABLE temp_qb_po ADD CONSTRAINT temp_qb_po_inv_num_orders_inv_num FOREIGN KEY (inv_num) REFERENCES orders(inv_num);
ALTER TABLE temp_qb_po_line ADD CONSTRAINT temp_qb_po_line_qb_prod_id_temp_acc_quickbooks_listid FOREIGN KEY (qb_prod_id) REFERENCES temp_acc(quickbooks_listid);
ALTER TABLE temp_qb_po_line ADD CONSTRAINT temp_qb_po_line_qb_inv_num_temp_qb_po_inv_num FOREIGN KEY (qb_inv_num) REFERENCES temp_qb_po(inv_num);
