Permalink
Browse files

Upgraded dbmigrate to 0.9. Added the Flash Wrapper plugin.

  • Loading branch information...
1 parent 932ab93 commit f33d49dd4f640dc20c09e5b3d39522ad3e87958f @russjohnson committed Aug 21, 2012
View
BIN plugins/FlashWrapper-0.1.zip
Binary file not shown.
View
BIN plugins/dbmigrate-0.7.2.zip
Binary file not shown.
View
BIN plugins/dbmigrate-0.9.zip
Binary file not shown.
View
75 plugins/dbmigrate/DBMigrate.cfc
@@ -1,7 +1,7 @@
<cfcomponent output="false" mixin="none" environment="design,development,maintenance">
<cffunction name="init">
- <cfset this.version = "1.0,1.0.1,1.0.2,1.0.3,1.0.4,1.0.5,1.1,1.1.3,1.1.4,1.1.5">
+ <cfset this.version = "1.0,1.0.1,1.0.2,1.0.3,1.0.4,1.0.5,1.1,1.1.3,1.1.4,1.1.5,1.1.6">
<cfreturn this>
</cffunction>
@@ -25,39 +25,47 @@
<cfset loc.migration = loc.migrations[loc.i]>
<cfif loc.migration.version lte arguments.version><cfbreak></cfif>
<cfif loc.migration.status eq "migrated">
- <cftry>
- <cfset loc.feedback = loc.feedback & "#chr(13)#------- " & loc.migration.cfcfile & " #RepeatString("-",Max(5,50-Len(loc.migration.cfcfile)))##chr(13)#">
- <cfset Request.migrationOutput = "">
- <cfset Request.migrationSQLFile = "#loc.sqlPath#/#loc.migration.cfcfile#_down.sql">
- <cffile action="write" file="#Request.migrationSQLFile#" output="">
- <cfset loc.migration.cfc.down()>
- <cfset loc.feedback = loc.feedback & Request.migrationOutput>
- <cfset $removeVersionAsMigrated(loc.migration.version)>
- <cfcatch type="any">
- <cfset loc.feedback = loc.feedback & "Error migrating to #loc.migration.version#.#chr(13)##CFCATCH.Message##chr(13)##CFCATCH.Detail##chr(13)#">
- <cfbreak>
- </cfcatch>
- </cftry>
+ <!--- <cftransaction action="begin"> --->
+ <cftry>
+ <cfset loc.feedback = loc.feedback & "#chr(13)#------- " & loc.migration.cfcfile & " #RepeatString("-",Max(5,50-Len(loc.migration.cfcfile)))##chr(13)#">
+ <cfset Request.migrationOutput = "">
+ <cfset Request.migrationSQLFile = "#loc.sqlPath#/#loc.migration.cfcfile#_down.sql">
+ <cffile action="write" file="#Request.migrationSQLFile#" output="">
+ <cfset loc.migration.cfc.down()>
+ <cfset loc.feedback = loc.feedback & Request.migrationOutput>
+ <cfset $removeVersionAsMigrated(loc.migration.version)>
+ <cfcatch type="any">
+ <cfset loc.feedback = loc.feedback & "Error migrating to #loc.migration.version#.#chr(13)##CFCATCH.Message##chr(13)##CFCATCH.Detail##chr(13)#">
+ <!--- <cftransaction action="rollback" /> --->
+ <cfbreak>
+ </cfcatch>
+ </cftry>
+ <!--- <cftransaction action="commit" />
+ </cftransaction> --->
</cfif>
</cfloop>
<cfelse>
<cfset loc.feedback = "Migrating from #loc.currentVersion# up to #arguments.version#.#chr(13)#">
<cfloop index="loc.i" from="1" to="#ArrayLen(loc.migrations)#">
<cfset loc.migration = loc.migrations[loc.i]>
<cfif loc.migration.version lte arguments.version and loc.migration.status neq "migrated">
- <cftry>
- <cfset loc.feedback = loc.feedback & "#chr(13)#-------- " & loc.migration.cfcfile & " #RepeatString("-",Max(5,50-Len(loc.migration.cfcfile)))##chr(13)#">
- <cfset Request.migrationOutput = "">
- <cfset Request.migrationSQLFile = "#loc.sqlPath#/#loc.migration.cfcfile#_up.sql">
- <cffile action="write" file="#Request.migrationSQLFile#" output="">
- <cfset loc.migration.cfc.up()>
- <cfset loc.feedback = loc.feedback & Request.migrationOutput>
- <cfset $setVersionAsMigrated(loc.migration.version)>
- <cfcatch type="any">
- <cfset loc.feedback = loc.feedback & "Error migrating to #loc.migration.version#.#chr(13)##CFCATCH.Message##chr(13)##CFCATCH.Detail##chr(13)#">
- <cfbreak>
- </cfcatch>
- </cftry>
+ <!--- <cftransaction action="begin"> --->
+ <cftry>
+ <cfset loc.feedback = loc.feedback & "#chr(13)#-------- " & loc.migration.cfcfile & " #RepeatString("-",Max(5,50-Len(loc.migration.cfcfile)))##chr(13)#">
+ <cfset Request.migrationOutput = "">
+ <cfset Request.migrationSQLFile = "#loc.sqlPath#/#loc.migration.cfcfile#_up.sql">
+ <cffile action="write" file="#Request.migrationSQLFile#" output="">
+ <cfset loc.migration.cfc.up()>
+ <cfset loc.feedback = loc.feedback & Request.migrationOutput>
+ <cfset $setVersionAsMigrated(loc.migration.version)>
+ <cfcatch type="any">
+ <cfset loc.feedback = loc.feedback & "Error migrating to #loc.migration.version#.#chr(13)##CFCATCH.Message##chr(13)##CFCATCH.Detail##chr(13)#">
+ <!--- <cftransaction action="rollback" /> --->
+ <cfbreak>
+ </cfcatch>
+ </cftry>
+ <!--- <cftransaction action="commit" />
+ </cftransaction> --->
<cfelseif loc.migration.version gt arguments.version>
<cfbreak>
</cfif>
@@ -154,9 +162,10 @@
<cfargument name="migrationName" type="string" required="true" />
<cfargument name="templateName" type="string" required="true" />
<cfargument name="migrationPrefix" type="string" required="false" default="" />
- <cfset var loc = {}>
- <cfset loc.migrationsPath = expandPath("db/migrate")>
- <cfset loc.templateFile = expandPath("plugins/dbmigrate/templates") & "/" & arguments.templateName & ".cfc">
+ <cfset var loc = {}/>
+ <cfset loc.migrationsPath = expandPath("db/migrate")/>
+ <cfset loc.templateFile = expandPath("plugins/dbmigrate/templates") & "/" & arguments.templateName & ".cfc"/>
+ <cfset loc.extendsPath = "plugins.dbmigrate.Migration"/>
<cfif not FileExists(loc.templateFile)>
<cfreturn "Template #arguments.templateName# could not be found">
</cfif>
@@ -166,7 +175,11 @@
<cftry>
<cffile action="read" file="#loc.templateFile#" variable="loc.templateContent">
- <cfset loc.templateContent = replace(loc.templateContent, "[extends]", "plugins.dbmigrate.Migration")>
+ <cfif Len(Trim(application.wheels.rootcomponentpath)) GT 0>
+ <cfset loc.extendsPath = application.wheels.rootcomponentpath & ".plugins.dbmigrate.Migration"/>
+ </cfif>
+
+ <cfset loc.templateContent = replace(loc.templateContent, "[extends]", loc.extendsPath)>
<cfset loc.templateContent = replace(loc.templateContent, "[description]", replace(arguments.migrationName,'"','&quot;','ALL'))>
<cfset loc.migrationFile = REREplace(arguments.migrationName,"[^A-z0-9]+"," ","ALL")>
View
51 plugins/dbmigrate/Migration.cfc
@@ -52,8 +52,15 @@
<cffunction name="dropTable" returntype="void" access="public" hint="drops a table from the database">
<cfargument name="name" type="string" required="true" hint="table name">
<cfscript>
- $execute(this.adapter.dropTable(name=arguments.name));
- announce("Dropped table #arguments.name#");
+ var loc = {};
+ loc.foreignKeys = $getForeignKeys(arguments.name);
+ loc.iEnd = ListLen(loc.foreignKeys);
+ for (loc.i=1; loc.i <= loc.iEnd; loc.i++) {
+ loc.foreignKeyName = ListGetAt(loc.foreignKeys,loc.i);
+ dropForeignKey(table=arguments.name,keyname=loc.foreignKeyName);
+ }
+ $execute(this.adapter.dropTable(name=arguments.name));
+ announce("Dropped table #arguments.name#");
</cfscript>
</cffunction>
@@ -168,27 +175,27 @@
<cffunction name="addRecord" returntype="void" access="public" hint="adds a record to a table">
<cfargument name="table" type="string" required="true" hint="table name">
<cfscript>
- var loc = {};
- loc.columnNames = "";
- loc.columnValues = "";
- for (loc.key in arguments) {
- if(loc.key neq "table") {
- loc.columnNames = ListAppend(loc.columnNames,this.adapter.quoteColumnName(loc.key));
- if(IsNumeric(arguments[loc.key])) {
- loc.columnValues = ListAppend(loc.columnValues,arguments[loc.key]);
- } else if(IsBoolean(arguments[loc.key])) {
- loc.columnValues = ListAppend(loc.columnValues,IIf(arguments[loc.key],1,0));
- } else if(IsDate(arguments[loc.key])) {
- loc.columnValues = ListAppend(loc.columnValues,"#arguments[loc.key]#");
- } else {
- loc.columnValues = ListAppend(loc.columnValues,"'#arguments[loc.key]#'");
+ var loc = {};
+ loc.columnNames = "";
+ loc.columnValues = "";
+ for (loc.key in arguments) {
+ if(loc.key neq "table") {
+ loc.columnNames = ListAppend(loc.columnNames,this.adapter.quoteColumnName(loc.key));
+ if(IsNumeric(arguments[loc.key])) {
+ loc.columnValues = ListAppend(loc.columnValues,arguments[loc.key]);
+ } else if(IsBoolean(arguments[loc.key])) {
+ loc.columnValues = ListAppend(loc.columnValues,IIf(arguments[loc.key],1,0));
+ } else if(IsDate(arguments[loc.key])) {
+ loc.columnValues = ListAppend(loc.columnValues,"#arguments[loc.key]#");
+ } else {
+ loc.columnValues = ListAppend(loc.columnValues,"'#ReplaceNoCase(arguments[loc.key],"'","''","all")#'");
+ }
}
}
- }
- if(loc.columnNames != '') {
- $execute("INSERT INTO #this.adapter.quoteTableName(LCase(arguments.table))# ( #loc.columnNames# ) VALUES ( #loc.columnValues# )");
- announce("Added record to table #arguments.table#");
- }
+ if(loc.columnNames != '') {
+ $execute("INSERT INTO #this.adapter.quoteTableName(LCase(arguments.table))# ( #loc.columnNames# ) VALUES ( #loc.columnValues# )");
+ announce("Added record to table #arguments.table#");
+ }
</cfscript>
</cffunction>
@@ -205,6 +212,8 @@
loc.update = loc.update & "#arguments[loc.key]#";
} else if(IsBoolean(arguments[loc.key])) {
loc.update = loc.update & "#IIf(arguments[loc.key],1,0)#";
+ } else if(IsDate(arguments[loc.key])) {
+ loc.update = loc.update & "#arguments[loc.key]#";
} else {
loc.update = loc.update & "'#arguments[loc.key]#'";
}
View
9 plugins/dbmigrate/adapters/Abstract.cfc
@@ -73,9 +73,12 @@
<cfargument name="value" type="string" required="true" hint="value to be quoted">
<cfargument name="options" type="struct" required="false" default="#StructNew()#" hint="column options">
<cfscript>
- if(StructKeyExists(arguments.options,'type') && ListFindNoCase("text,string,binary,date,datetime,time,timestamp",arguments.options.type)) {
- arguments.value = "'#arguments.value#'";
- }
+ if(StructKeyExists(arguments.options,'type') && ListFindNoCase("binary,date,datetime,time,timestamp",arguments.options.type)) {
+ arguments.value = "'#arguments.value#'";
+ }
+ else if(StructKeyExists(arguments.options,'type') && ListFindNoCase("text,string",arguments.options.type)) {
+ arguments.value = "'#ReplaceNoCase(arguments.value,"'","''")#'";
+ }
</cfscript>
<cfreturn arguments.value>
</cffunction>
View
17 plugins/dbmigrate/basefunctions.cfm
@@ -60,8 +60,16 @@
<cffunction name="$getColumns" returntype="string" access="public" output="false">
<cfargument name="tableName" type="string" required="yes" hint="table name">
<cfset var loc = {}>
- <!--- use cfdbinfo --->
- <cfset loc.columns = $dbinfo(type="columns",table=arguments.tableName,datasource=application.wheels.dataSourceName,username=application.wheels.dataSourceUserName,password=application.wheels.dataSourcePassword)>
+ <cfif $getDBType() eq "Oracle">
+ <!--- oracle thin client jdbc throws error when usgin cfdbinfo to access column data --->
+ <!--- because of this error wheels can't load models anyway so maybe we don't need to support this driver --->
+ <cfquery name="loc.columns" datasource="#application.wheels.dataSourceName#" username="#application.wheels.dataSourceUserName#" password="#application.wheels.dataSourcePassword#">
+ SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = '#this.name#'
+ </cfquery>
+ <cfelse>
+ <!--- use cfdbinfo --->
+ <cfset loc.columns = $dbinfo(type="columns",table=arguments.tableName,datasource=application.wheels.dataSourceName,username=application.wheels.dataSourceUserName,password=application.wheels.dataSourcePassword)>
+ </cfif>
<cfreturn ValueList(loc.columns.COLUMN_NAME)>
</cffunction>
@@ -70,6 +78,7 @@
<cfargument name="columnName" type="string" required="yes" hint="column name">
<cfset var loc = {}>
<cfdbinfo name="loc.columns" type="columns" table="#arguments.tableName#" datasource="#application.wheels.dataSourceName#" username="#application.wheels.dataSourceUserName#" password="#application.wheels.dataSourcePassword#">
+ <!--- <cfdump var="#loc#" abort> --->
<cfscript>
loc.columnDefinition = "";
loc.iEnd = loc.columns.RecordCount;
@@ -87,7 +96,9 @@
} else {
loc.columnDefinition = loc.columnDefinition & " NOT NULL";
}
- if(ListFindNoCase("char,varchar,binary,varbinary",loc.columnType)) {
+ if(Len(loc.columns["COLUMN_DEFAULT_VALUE"][loc.i]) == 0) {
+ loc.columnDefinition = loc.columnDefinition & " DEFAULT NULL";
+ } else if(ListFindNoCase("char,varchar,binary,varbinary",loc.columnType)) {
loc.columnDefinition = loc.columnDefinition & " DEFAULT '#loc.columns["COLUMN_DEFAULT_VALUE"][loc.i]#'";
} else if(ListFindNoCase("int,bigint,smallint,tinyint,decimal,float,double",loc.columnType)) {
loc.columnDefinition = loc.columnDefinition & " DEFAULT #loc.columns["COLUMN_DEFAULT_VALUE"][loc.i]#";
View
13 plugins/dbmigrate/index.cfm
@@ -1,5 +1,8 @@
<cfsetting enablecfoutputonly="true">
+<cfset dbmigrateMeta = {}>
+<cfset dbmigrateMeta.version = "0.9">
+
<cfif isDefined("Form.version")>
<cfset flashInsert(dbmigrateFeedback=application.wheels.plugins.dbmigrate.migrateTo(Form.version))>
<cfset redirectTo(back=true)>
@@ -8,6 +11,11 @@
<cfparam name="Form.migrationPrefix" default="">
<cfset flashInsert(dbmigrateFeedback2=application.wheels.plugins.dbmigrate.createMigration(Form.migrationName,Form.templateName,Form.migrationPrefix))>
<cfset redirectTo(back=true)>
+<cfelseif isDefined("url.migrateToVersion") And Len(Trim(url.migrateToVersion)) GT 0 And IsNumeric(url.migrateToVersion)>
+ <cfif isDefined("url.password") And Trim(url.password) EQ application.wheels.reloadPassword>
+ <cfset flashInsert(dbmigrateFeedback=application.wheels.plugins.dbmigrate.migrateTo(url.migrateToVersion))>
+ <cfset redirectTo(back=true)>
+ </cfif>
</cfif>
<!--- Get current database version --->
@@ -25,7 +33,7 @@
<cfinclude template="css.cfm">
-<h1>DBMigrate</h1>
+<h1>DBMigrate v#dbmigrateMeta.version#</h1>
<h2>inspired by Active Record migrations</h2>
<p>Database Migrations are an easy way to build and alter your database structure using cfscript.</p>
@@ -96,6 +104,9 @@
<option value="create-record">Create record</option>
<option value="update-record">Update record</option>
<option value="remove-record">Remove record</option>
+ <option value="">-- Miscellaneous Operations --</option>
+ <option value="announce">Announce operation</option>
+ <option value="execute">Execute operation</option>
</select>
</p>
View
2 plugins/richtext/RichText.cfc
@@ -26,7 +26,7 @@
<cfargument name="includeJSLibrary" type="string" required="false" default="true" hint="Tells the plugin wether or not it should add the primary JS library to the html head section.">
<cfscript>
var loc = {};
- $args(name="textArea", reserved="name", args=arguments);
+ $insertDefaults(name="textArea", reserved="name", input=arguments);
loc.before = $formBeforeElement(argumentCollection=arguments);
loc.after = $formAfterElement(argumentCollection=arguments);
arguments.name = $tagName(arguments.objectName, arguments.property);

0 comments on commit f33d49d

Please sign in to comment.