 CREATE INDEX idx_lens_0 ON lens ( lenstypeid );
 
 CREATE TABLE model ( 
-	id                   int  NOT NULL  ,
+	id                   int  NOT NULL  AUTO_INCREMENT,
 	name                 varchar(500)  NOT NULL  ,
 	styleid              int    ,
 	sku                  varchar(20)    ,

	inserttime           timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP ,
	validfrom            timestamp   DEFAULT 0 ,
	validto              timestamp   DEFAULT 0 ,
	CONSTRAINT pk_lens UNIQUE ( id ) 
 ) engine=InnoDB;

CREATE INDEX idx_lens ON lens ( sourceid );

CREATE TABLE source ( 
	id                   int  NOT NULL  AUTO_INCREMENT,
	name                 varchar(30)  NOT NULL  ,
	description          varchar(150)    ,
	active               bit  NOT NULL DEFAULT 1 ,
	inserttime           timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP ,
	validfrom            timestamp  DEFAULT 0 ,
	validto              timestamp  DEFAULT 0 ,
	CONSTRAINT pk_source UNIQUE ( id ) ,
	CONSTRAINT pk_source_0 PRIMARY KEY ( id )
 ) engine=InnoDB;

CREATE TABLE style ( 
	id                   int  NOT NULL  AUTO_INCREMENT,
	name                 varchar(100)  NOT NULL  ,
	basecurveid          int    ,
	url                  varchar(20000)    ,
	sourceid             int  NOT NULL  ,
	inserttime           timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP ,
	validfrom            timestamp  DEFAULT 0 ,
	validto              timestamp  DEFAULT 0 ,
	CONSTRAINT pk_style UNIQUE ( id ) ,
	CONSTRAINT pk_style_0 PRIMARY KEY ( id )
 );

CREATE INDEX idx_style ON style ( sourceid );

CREATE TABLE basecurve ( 
	id                   int  NOT NULL  AUTO_INCREMENT,
	name                 varchar(20)  NOT NULL  ,
	sourceid             int    ,
	inserttime           timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP ,
	CONSTRAINT pk_basecurve PRIMARY KEY ( id )
 ) engine=InnoDB;

CREATE INDEX idx_basecurve ON basecurve ( sourceid );

CREATE TABLE collection ( 
	id                   int  NOT NULL  AUTO_INCREMENT,
	name                 varchar(100)  NOT NULL  ,
	url                  varchar(2000)    ,
	sourceid             int    ,
	inserttime           timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP ,
	validfrom            timestamp   DEFAULT 0 ,
	validto              timestamp   DEFAULT 0 ,
	CONSTRAINT pk_collection PRIMARY KEY ( id )
 ) engine=InnoDB;

CREATE INDEX idx_collection ON collection ( sourceid );

CREATE TABLE family ( 
	id                   int  NOT NULL  AUTO_INCREMENT,
	name                 varchar(80)    ,
	sourceid             int  NOT NULL  ,
	inserttime           timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP ,
	validfrom            timestamp  DEFAULT 0 ,
	validto              timestamp  DEFAULT 0 ,
	CONSTRAINT pk_family UNIQUE ( id ) ,
	CONSTRAINT pk_family_0 PRIMARY KEY ( id )
 );

CREATE INDEX idx_family ON family ( sourceid );

CREATE TABLE familystylemap ( 
	id                   int  NOT NULL  AUTO_INCREMENT,
	familyid             int  NOT NULL  ,
	styleid              int  NOT NULL  ,
	sourceid             int    ,
	inserttime           timestamp  NOT NULL DEFAULT CURRENT_TIMESTAMP ,
	validfrom            timestamp  DEFAULT 0 ,
	validto              timestamp  DEFAULT 0 ,
	CONSTRAINT pk_familystylemap PRIMARY KEY ( id )
 );

CREATE INDEX idx_familystylemap ON familystylemap ( familyid );
