#12 Installation - Automatic table creation

open
nobody
5
2013-11-19
2013-11-19
Kevin Lietaer
No

When you "install" the Knowledge Base, it's a good idea to add the create queries into the code. Not everyone uses ssh acces or understands it, so they don't really know they have to do the create tables themselves.

Before line 118 in install/index.php ( before the create user ):

$mysqldb->query("CREATE TABLE IF NOT EXISTS articles ( FileID int(3) unsigned NOT NULL auto_increment, ParentID int(3) unsigned NOT NULL default '0', AuthorID mediumint(8) unsigned NOT NULL default '0', Title varchar(50) NOT NULL default '', Keyw varchar(80) default NULL, Articledata longtext, Approved char(1) default 'N', Views int(10) default '0', RatingTotal varchar(5) NOT NULL default '0', RatedTotal varchar(5) NOT NULL default '0', SubmitDate timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (FileID), KEY Keyw (Keyw) );");
$mysqldb->query("CREATE TABLE IF NOT EXISTS articles ( FileID int(3) unsigned NOT NULL auto_increment, ParentID int(3) unsigned NOT NULL default '0', AuthorID mediumint(8) unsigned NOT NULL default '0', Title varchar(50) NOT NULL default '', Keyw varchar(80) default NULL, Articledata longtext, Approved char(1) default 'N', Views int(10) default '0', RatingTotal varchar(5) NOT NULL default '0', RatedTotal varchar(5) NOT NULL default '0', SubmitDate timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (FileID), KEY Keyw (Keyw) );");
$mysqldb->query("CREATE TABLE IF NOT EXISTS authors ( AuthorID mediumint(8) unsigned NOT NULL auto_increment, UserName varchar(20) NOT NULL, FirstName varchar(15) NOT NULL, LastName varchar(30) NOT NULL, Email varchar(40) default NULL, EmailMD5 varchar(50) default NULL, Approved char(1) default 'N', Passwd varchar(52) NOT NULL, RegistrationDate datetime NOT NULL, PRIMARY KEY (AuthorID), UNIQUE KEY UserName (UserName), KEY FirstName (FirstName), KEY LastName (LastName), KEY Passwd (Passwd) );");
$mysqldb->query("CREATE TABLE IF NOT EXISTS tags ( id int(10) unsigned NOT NULL auto_increment, fileid int(10) unsigned NOT NULL, tag char(64) default NULL, PRIMARY KEY (id) );");
$mysqldb->query("CREATE TABLE IF NOT EXISTS uploads ( UploadID int(10) unsigned NOT NULL auto_increment, AuthorID mediumint(8) unsigned NOT NULL, FileID mediumint(8) unsigned NOT NULL, FileName varchar(60) NOT NULL, FileSize int(6) unsigned NOT NULL, FileType varchar(30) NOT NULL, FileDescription varchar(100) default NULL, UploadDate datetime NOT NULL, PRIMARY KEY (UploadID), KEY FileName (FileName), KEY FileID (FileID), KEY AuthorID (AuthorID) );");

( since I can't seem to upload my new file?? just take the sql code from your sql file and paste it in the class )

Discussion

  • Kevin Lietaer
    Kevin Lietaer
    2013-11-19

    To improve on this idea, it might be a good idea to test if the tables in question already exist or not, since the installation can't be handle properly if one of the tables is already used by other code from other developper.