Class: BradyW::Sqlcmd
- Includes:
- WindowsPaths
- Defined in:
- lib/sqlcmd.rb
Overview
Runs SQLcmd to run supplied SQL scripts. This task will roll up all supplied SQL script files into 1 SQL file before running it in order to speed up the tasks. The “-e” flag is used so that all statements are echo’ed to stdout.
Instance Attribute Summary collapse
-
#files ⇒ Object
Required Which SQL scripts do you want to run? Everything in this path will be run with this script.
-
#makedynamic ⇒ Object
Optional Setting this to true will NOT execute sqlcmd at all, but instead will go through the source files supplied and replace any hard coded host names, database names, or any other variables with sqlcmd style $(variable)s to make scripts more dynamic.
-
#variables ⇒ Object
writeonly
Optional By default, several variables are passed into SQLCMD based on the config file.
-
#version ⇒ Object
Optional Version of SQL Server’s sqlcmd to use.
Attributes inherited from BaseTask
Instance Method Summary collapse
- #credentials ⇒ Object
-
#credentials=(value) ⇒ Object
Optional Which set of DB credentials should be used? :system - for creation/deletion of databases :objectcreation - for adding/creating objects within a database :general - DEFAULT - for adding/deleting rows within a database (use this for code).
Instance Attribute Details
#files ⇒ Object
Required Which SQL scripts do you want to run? Everything in this path will be run with this script. It’s recommended that you arrange your structure like the one below. If you do, the generated meta script will have nice comments that indicate what it’s currently running
somedirectory
01-tables
01-table1.sql
02-table2.sql
02-indexes
21 22 23 |
# File 'lib/sqlcmd.rb', line 21 def files @files end |
#makedynamic ⇒ Object
Optional Setting this to true will NOT execute sqlcmd at all, but instead will go through the source files supplied and replace any hard coded host names, database names, or any other variables with sqlcmd style $(variable)s to make scripts more dynamic. It’s useful when taking scripts creating on a single developer machine and prepping them for checkin. Default is false.
40 41 42 |
# File 'lib/sqlcmd.rb', line 40 def makedynamic @makedynamic end |
#variables=(value) ⇒ Object
Optional By default, several variables are passed into SQLCMD based on the config file. Add yours in here as key value pairs if you want to send more. The following will be set by default:
-
dbname - all credentials
-
sqlserverdatadirectory - only when using :system credentials
-
dbuser -> general user, all credentials
-
dbpassword - > general password, only when using :system credentials
33 34 35 |
# File 'lib/sqlcmd.rb', line 33 def variables=(value) @variables = value end |
#version ⇒ Object
Optional Version of SQL Server’s sqlcmd to use. Defaults to SQL Server 2008.
24 25 26 |
# File 'lib/sqlcmd.rb', line 24 def version @version end |
Instance Method Details
#credentials ⇒ Object
51 52 53 |
# File 'lib/sqlcmd.rb', line 51 def credentials @credentials || :general end |
#credentials=(value) ⇒ Object
Optional Which set of DB credentials should be used? :system - for creation/deletion of databases :objectcreation - for adding/creating objects within a database :general - DEFAULT - for adding/deleting rows within a database (use this for code)
46 47 48 49 |
# File 'lib/sqlcmd.rb', line 46 def credentials=(value) BaseTask.validate value, "credentials", Database::CREDENTIALS @credentials = value end |