Last active
September 18, 2019 18:28
-
-
Save timcunningham/83e71ccb8a63298ae9a3802f33f54afa to your computer and use it in GitHub Desktop.
Build datasources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
param name="suffix" default="default,Config,Insured,InsuredPortal,Log,Rate,System,VIN"; | |
param name="prefix" default="Evergreen"; | |
param name="cfAdminPass" default=""; | |
param name="userName" default="sa"; | |
param name="password" default=""; | |
param name="dbHost" default="evergreen.qa.ptssql.com"; | |
// This section actually does the work based on the form input values | |
if (isDefined("form.action") && form.action=="doit") { | |
adminObj = createObject("component","cfide.adminapi.administrator"); | |
adminObj.login("#cfadminpass#"); | |
dsnAPI = createObject("component" , "cfide.adminapi.datasource"); | |
createSystemDSN(argumentCollection=form); | |
abort; | |
} | |
// This is the master function | |
function createSystemDSN(required string prefix, required suffix, required string dbHost, required string username, required string password, required numeric port=1433, required string driver="MSSQLServer") | |
hint="Create a series of databases with the same prefix and a list of different suffix names example myDBLog for database myDB_Log" | |
{ | |
argCollection = arguments; | |
for (name in listToArray(arguments.suffix)) { | |
argCollection.suffix = name; | |
composeDSN(argumentCollection=argCollection); | |
} | |
} | |
// Supporting Functions below | |
function composeDSN(required string prefix, required suffix, required string dbHost, required string username, required string password, required numeric port=1433, required string driver="MSSQLServer") | |
hint="Build the name of the Datasource and the name of the Database" | |
{ | |
arguments.name = composeDSName(prefix, suffix); | |
arguments.databaseName = composeDatabaseName(prefix, suffix); | |
makeDSN(argumentCollection=arguments); | |
writeoutput("#arguments.name# DSN made for #arguments.databaseName#<br>"); | |
} | |
function composeDSName(required string prefix, required string suffix) | |
hint="Datasource is Main DB prefix and suffix with no space. default suffix means no suffix just the prefix name ex: myDB rather than myDB_Log" | |
{ | |
if (arguments.suffix=="default") { | |
arguments.suffix = ""; | |
} | |
return arguments.prefix & arguments.suffix; | |
} | |
function composeDatabaseName(required string prefix, required string suffix) | |
hint="Actual name of the DB is the main db name with underscore and suffix. Excepting default which gets no suffix" | |
{ | |
if (arguments.suffix=="default") { | |
arguments.suffix = ""; | |
} | |
else { | |
arguments.suffix = "_" & suffix; | |
} | |
return arguments.prefix & arguments.suffix; | |
} | |
function makeDSN(required string name, required string databaseName, required string dbHost, required string username, required string password, required numeric port, required string driver="MSSQLServer") | |
hint="Tell ColdFusion Admin to build the Datasource" | |
{ | |
var dsn = { | |
driver = '#arguments.driver#', | |
name = '#arguments.name#', | |
host = '#arguments.dbHost#', | |
port = '#arguments.port#', | |
database = '#arguments.databaseName#', | |
username = '#arguments.username#', | |
password = '#arguments.password#', | |
args = '' | |
}; | |
dsnAPI.setMSSQL(argumentCollection=dsn); | |
} | |
</cfscript> | |
<!--- ****************** ENTRY FORM ********************** ---> | |
<cfoutput> | |
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> | |
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> | |
<!------ Include the above in your HEAD tag ----------> | |
<form action="" method="post"> | |
<div class="container contact"> | |
<div class="row"> | |
<div class="col-md-3"> | |
<div class="contact-info"> | |
<h2>Datasource</h2> | |
<h4>Create Standard 6.0 DSNs</h4> | |
</div> | |
</div> | |
<div class="col-md-9"> | |
<div class="contact-form"> | |
<div class="form-group"> | |
<label class="control-label col-sm-2" for="prefix">System:</label> | |
<div class="col-sm-10"> | |
<input type="text" class="form-control" id="prefix" placeholder="#prefix#" name="prefix" value="#prefix#"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label class="control-label col-sm-2" for="userName">DB User</label> | |
<div class="col-sm-10"> | |
<input type="text" class="form-control" id="userName" placeholder="#userName#" name="userName" value="#userName#"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label class="control-label col-sm-2" for="userName">DB Pass</label> | |
<div class="col-sm-10"> | |
<input type="password" class="form-control" id="password" placeholder="Password for database" name="password"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label class="control-label col-sm-2" for="cfAdminPass">CFAdmin Pass</label> | |
<div class="col-sm-10"> | |
<input type="password" class="form-control" id="cfAdminPass" placeholder="Your Local CF Admin Password" name="cfAdminPass"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label class="control-label col-sm-2" for="dbHost">DB Host Address</label> | |
<div class="col-sm-10"> | |
<input type="text" class="form-control" id="dbHost" placeholder="#dbHost#" name="dbHost" value="#dbHost#"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label class="control-label col-sm-2" for="suffix">Create List:</label> | |
<div class="col-sm-10"> | |
<textarea class="form-control" rows="5" id="suffix" name="suffix">#suffix#</textarea> | |
</div> | |
</div> | |
<div class="form-group"> | |
<div class="col-sm-offset-2 col-sm-10"> | |
<button type="submit" class="btn btn-default">Submit</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<input type="hidden" name="action" value="doit"> | |
</form> | |
</cfoutput> | |
<style> | |
body{ | |
background-color: #25274d; | |
} | |
.contact{ | |
padding: 4%; | |
height: 400px; | |
} | |
.col-md-3{ | |
background: #ff9b00; | |
padding: 4%; | |
border-top-left-radius: 0.5rem; | |
border-bottom-left-radius: 0.5rem; | |
} | |
.contact-info{ | |
margin-top:10%; | |
} | |
.contact-info img{ | |
margin-bottom: 15%; | |
} | |
.contact-info h2{ | |
margin-bottom: 10%; | |
} | |
.col-md-9{ | |
background: #fff; | |
padding: 3%; | |
border-top-right-radius: 0.5rem; | |
border-bottom-right-radius: 0.5rem; | |
} | |
.contact-form label{ | |
font-weight:600; | |
} | |
.contact-form button{ | |
background: #25274d; | |
color: #fff; | |
font-weight: 600; | |
width: 25%; | |
} | |
.contact-form button:focus{ | |
box-shadow:none; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment