As i tried to analyse the CSV file, the part of data that is common for a product with different models is ProductID, MovieTitle, Store, Category, SubCategory.
So I have split the data between 2 tables (Product and Product_models). Product table (INNODB) contains the following as columns
- Product_id (type: int(6), Primary Key)
- Name (type: varchar(250))
- store (type: varchar(45))
- cat_id (type: int(6))
Product_models (MyISM) has the following as columns
- product_id (type: int(6), primary key)
- model_id (type: int(6), primary key, auto increment)
- price (type: int(7))
- shipping_duration (type: int(2))
For storing both Category and subcategory, I chose a single table named Category (INNODB) with an extra column as Parent_id. Its structure is as below
- cat_id (type: int(6), primary key)
- cat_name (type: varchar(40))
- parent_id (type: int(6), primary key)
- deleted (type: tinyint(1))
The purpose of choosing a single table for storing category and its subcategory is to reduce another table. The relations between any 2 categories can be mainted by simply assinging cat_id of parent to parent_id value of subcategory.
I choose MyISM db for product_models with a combination of model_id with auto_increment and product_id as primary key so that there is no need to read the number of already existing models for a given product to calculate model_id for next insert on same product.
I choose codeigniter as a framework just because I work on it daily. The default controller is welcome controller where the complete business logic code is available. Views are available in application/views. Database interactions for inserts are done using models which are found in application/models.
CSV file is placed in temp folder at root level along with MySQL schema creation file (unbxd schema.sql).
Dependencies:
- Please use unbxd schema.sql to create database.
- Please set appropriate values for database connection in application/config/database.php.
- To upload data from csv file into respective database please access localhost/unbxd/welcome/saveUploadedFile.
- Please enable rewrite_module for apache.
- localhost/unbxd to search for products.