 	<cfset loc.ident = "IDENTITY">
 </cfif>
 
-<cfset tables = "users,photogalleries,photogalleryphotos,posts,authors,classifications,comments,profiles,tags,cities,shops,userphotos">
-<cfloop list="#tables#" index="loc.i">
-	<cftry>
+<!--- get a listing of all the tables and view in the database --->
+<cfdbinfo name="loc.dbinfo" datasource="wheelstestdb" type="tables">
+<cfset loc.tableList = ValueList(loc.dbinfo.table_name, chr(7))>
+
+<!--- list of tables to delete --->
+<cfset loc.tables = "authors,cities,classifications,comments,photogalleries,photogalleryphotos,posts,profiles,shops,tags,users">
+<cfloop list="#loc.tables#" index="loc.i">
+	<cfif ListFindNoCase(loc.tableList, loc.i, chr(7))>
+		<cfquery name="loc.query" datasource="wheelstestdb">
+		DROP TABLE #loc.i#
+		</cfquery>
+	</cfif>
+</cfloop>
+
+<!--- list of views to delete --->
+<cfset loc.views = "userphotos">
+<cfloop list="#loc.views#" index="loc.i">
+	<cfif ListFindNoCase(loc.tableList, loc.i, chr(7))>
 		<cfquery name="loc.query" datasource="wheelstestdb">
 		DROP VIEW #loc.i#
 		</cfquery>
-	<cfcatch>
-	</cfcatch>
-	</cftry>
-	<cftry>
-		<cfquery name="loc.query" datasource="wheelstestdb">
-		DROP TABLE #loc.i#
-		</cfquery>
-	<cfcatch>
-	</cfcatch>
-	</cftry>
-</cfloop>
+	</cfif>
+</cfloop>
+
+
+<!--- 
+create tables
+ --->
+<cfquery name="loc.query" datasource="wheelstestdb">
+CREATE TABLE authors
+(
+	id int NOT NULL #loc.ident# PRIMARY KEY,
+	firstname varchar(100) NOT NULL,
+	lastname varchar(100) NOT NULL
+)
+</cfquery>
+
+<cfquery name="loc.query" datasource="wheelstestdb">
+CREATE TABLE cities
+(
+	countyid char(4) NOT NULL,
+	citycode tinyint NOT NULL,
+	name varchar(50) NOT NULL,
+	PRIMARY KEY(countyid,citycode)
+)
+</cfquery>
+
+<cfquery name="loc.query" datasource="wheelstestdb">
+CREATE TABLE classifications
+(
+	id int NOT NULL #loc.ident# PRIMARY KEY,
+	postid int NOT NULL,
+	tagid int NOT NULL
+)
+</cfquery>
+
+<cfquery name="loc.query" datasource="wheelstestdb">
+CREATE TABLE comments
+(
+	id int NOT NULL #loc.ident# PRIMARY KEY,
+	postid int NOT NULL,
+	body text NOT NULL,
+	name varchar(100) NOT NULL,
+	url varchar(100) NULL,
+	email varchar(100) NULL,
+	createdat datetime NOT NULL
+)
+</cfquery>
+
+<cfquery name="loc.query" datasource="wheelstestdb">
+CREATE TABLE photogalleries
+(
+	photogalleryid int NOT NULL #loc.ident# PRIMARY KEY,
+	userid int NOT NULL,
+	title varchar(255) NOT NULL,
+	description text NOT NULL
+)
+</cfquery>
+
+<cfquery name="loc.query" datasource="wheelstestdb">
+CREATE TABLE photogalleryphotos
+(
+	photogalleryphotoid int NOT NULL #loc.ident# PRIMARY KEY,
+	photogalleryid int NOT NULL,
+	filename varchar(255) NOT NULL,
+	description varchar(255) NOT NULL,
+	filedata <cfif loc.db IS "microsoftsqlserver">image<cfelse>blob</cfif> NULL
+)
+</cfquery>
+
+<cfquery name="loc.query" datasource="wheelstestdb">
+CREATE TABLE posts
+(
+	id int NOT NULL #loc.ident# PRIMARY KEY,
+	authorid int NULL,
+	title varchar(250) NOT NULL,
+	body text NOT NULL,
+	createdat datetime NOT NULL,
+	updatedat datetime NOT NULL,
+	deletedat datetime NULL,
+	views int NOT NULL DEFAULT 0,
+	averagerating float NULL
+)
+</cfquery>
+
+<cfquery name="loc.query" datasource="wheelstestdb">
+CREATE TABLE profiles
+(
+	id int NOT NULL #loc.ident# PRIMARY KEY,
+	authorid int NULL,
+	dateofbirth datetime NOT NULL,
+	bio text NULL
+)
+</cfquery>
+
+<cfquery name="loc.query" datasource="wheelstestdb">
+CREATE TABLE shops
+(
+	shopid char(9) NOT NULL PRIMARY KEY,
+	citycode tinyint NULL,
+	name varchar(80) NOT NULL
+)
+</cfquery>
+
+<cfquery name="loc.query" datasource="wheelstestdb">
+CREATE TABLE tags
+(
+	id int NOT NULL #loc.ident# PRIMARY KEY,
+	name varchar(50) NOT NULL,
+	description varchar(50) NULL
+)
+</cfquery>
 
 <cfquery name="loc.query" datasource="wheelstestdb">
 CREATE TABLE users

)
</cfquery>

<cfquery name="loc.query" datasource="wheelstestdb">
CREATE TABLE photogalleries
(
	photogalleryid int NOT NULL #loc.ident# PRIMARY KEY,
	userid int NOT NULL,
	title varchar(255) NOT NULL,
	description text NOT NULL
)
</cfquery>

<cfquery name="loc.query" datasource="wheelstestdb">
CREATE TABLE photogalleryphotos
(
	photogalleryphotoid int NOT NULL #loc.ident# PRIMARY KEY,
	photogalleryid int NOT NULL,
	filename varchar(255) NOT NULL,
	description varchar(255) NOT NULL,
	filedata <cfif loc.db IS "microsoftsqlserver">image<cfelse>blob</cfif> NULL
)
</cfquery>

<cfquery name="loc.query" datasource="wheelstestdb">
CREATE TABLE posts
(
	id int NOT NULL #loc.ident# PRIMARY KEY,
	authorid int NULL,
	title varchar(250) NOT NULL,
	body text NOT NULL,
	createdat datetime NOT NULL,
	updatedat datetime NOT NULL,
	deletedat datetime NULL,
	views int NOT NULL DEFAULT 0,
	averagerating float NULL
)
</cfquery>

<cfquery name="loc.query" datasource="wheelstestdb">
CREATE TABLE authors
(
	id int NOT NULL #loc.ident# PRIMARY KEY,
	firstname varchar(100) NOT NULL,
	lastname varchar(100) NOT NULL
)
</cfquery>

<cfquery name="loc.query" datasource="wheelstestdb">
CREATE TABLE classifications
(
	id int NOT NULL #loc.ident# PRIMARY KEY,
	postid int NOT NULL,
	tagid int NOT NULL
)
</cfquery>

<cfquery name="loc.query" datasource="wheelstestdb">
CREATE TABLE comments
(
	id int NOT NULL #loc.ident# PRIMARY KEY,
	postid int NOT NULL,
	body text NOT NULL,
	name varchar(100) NOT NULL,
	url varchar(100) NULL,
	email varchar(100) NULL,
	createdat datetime NOT NULL
)
</cfquery>

<cfquery name="loc.query" datasource="wheelstestdb">
CREATE TABLE profiles
(
	id int NOT NULL #loc.ident# PRIMARY KEY,
	authorid int NULL,
	dateofbirth datetime NOT NULL,
	bio text NULL
)
</cfquery>

<cfquery name="loc.query" datasource="wheelstestdb">
CREATE TABLE tags
(
	id int NOT NULL #loc.ident# PRIMARY KEY,
	name varchar(50) NOT NULL,
	description varchar(50) NULL
)
</cfquery>

<cfquery name="loc.query" datasource="wheelstestdb">
CREATE TABLE cities
(
	countyid char(4) NOT NULL,
	citycode tinyint NOT NULL,
	name varchar(50) NOT NULL,
	PRIMARY KEY(countyid,citycode)
)
</cfquery>

<cfquery name="loc.query" datasource="wheelstestdb">
CREATE TABLE shops
(
	shopid char(9) NOT NULL PRIMARY KEY,
	citycode tinyint NULL,
	name varchar(80) NOT NULL
)
</cfquery>

<cfquery name="loc.query" datasource="wheelstestdb">
CREATE VIEW userphotos AS
SELECT u.id AS userid, u.username AS username, u.firstname AS firstname, u.lastname AS lastname, pg.title AS title, pg.photogalleryid AS photogalleryid
FROM users u INNER JOIN photogalleries pg ON u.id = pg.userid;
</cfquery>

<!--- populate with data --->
<cfset loc.user = model("user").create(

<!--- get the version of the database we're running against --->
<cfdbinfo name="loc.dbinfo" datasource="wheelstestdb" type="version">
<cfset loc.db = LCase(Replace(loc.dbinfo.database_productname, " ", "", "all"))>

<!--- handle differences in database for identity inserts --->
<cfif loc.db IS "microsoftsqlserver">
	<cfset loc.ident = "IDENTITY(1,1)">
<cfelseif loc.db IS "mysql">
