Created
July 2, 2021 16:03
-
-
Save dataders/0f9a823cbf45d4f705fd67b2a2fbbf19 to your computer and use it in GitHub Desktop.
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
<# | |
.SYNOPSIS | |
.DESCRIPTION | |
This script will configure a DBT setup | |
.EXAMPLE | |
./new-DBTConfig -Schemaid "XYZ" | |
.NOTES | |
.LINK | |
NA | |
#> | |
#Region Section Parameters and other declarations | |
#area for requirments /////// | |
#Requires -RunAsAdministrator | |
#Requires -Version 5.0 | |
[CmdletBinding(DefaultParameterSetName='standard')] | |
param( | |
[ValidateLength(3,10)] | |
[parameter(ParameterSetName='standard',Mandatory=$true)] | |
[string] | |
$schemaid | |
#[parameter(parametersetname='localrun',Mandatory=$true)][switch]$checklocal | |
) | |
#region configFiles | |
# time stamp run time | |
$starttime = "" | |
$starttime = Get-Date | |
#VS code workspace Json | |
$vscworkspacefile = @" | |
{ | |
"folders": [ | |
{ | |
"path": "../jaffle_shop_mssql" | |
} | |
], | |
"settings": { | |
}, | |
"extensions": { | |
"recommendations": [ | |
"ms-python.python" | |
"samuelcolvin.jinjahtml" | |
"bastienboutonnet.vscode-dbt" | |
"mechatroner.rainbow-csv" | |
"ms-vscode.azurecli" | |
] | |
} | |
} | |
"@ | |
#Yaml config | |
$profilefile = @" | |
jaffle_shop: | |
target: azsql | |
outputs: | |
azsql: | |
schema: $schemaid | |
type: sqlserver | |
driver: "ODBC Driver 17 for SQL Server" | |
host: dbtavatrain.database.windows.net | |
database: sandbox | |
authentication: CLI | |
port: 1433 | |
encrypt: True | |
trust_cert: True | |
"@ | |
#endregion config files | |
# Start of Script | |
Function Test-Appinstalled { | |
# used to test if an application is installed WIP , not used at the moment | |
} | |
Function InstallChoco { | |
# this function will install choco and required software for DBT. | |
# install choco using there provided documents | |
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) | |
#needs code to check if choco is installed | |
# Installs required software for DBT | |
choco install vscode anaconda3 git sql-server-management-studio azure-cli -y | |
#refresh ENV Vars for the system | |
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") | |
} | |
Function SetupVScode { | |
#create folder and clone to documents folder and clone repo to said folder | |
$folderdata = "$env:USERPROFILE" + "\documents\coderepo" | |
New-Item -Path $folderdata -ItemType Directory -ErrorAction SilentlyContinue | |
set-location $folderdata | |
git clone "https://github.com/dbt-msft/jaffle_shop_mssql" | |
#workspace creation | |
$vscworkspace = $folderdata + "\workspace" | |
New-Item -Path ($folderdata + "\workspace") -ItemType Directory -ErrorAction SilentlyContinue | |
$vscworkspacefile | out-file -FilePath ($vscworkspace + "\dbt-env-Python.code-workspace") -Encoding ascii -Force | |
} | |
Function ConfigPythonEnv { | |
#Configure anaconda for python 3.7.9 | |
$condarun = 'C:\tools\Anaconda3\shell\condabin\conda-hook.ps1' | |
& $condarun ; conda create -n dbtenv python=3.7.9 -y | |
& $condarun ; conda activate dbtenv | |
& pip install azure-cli | |
& pip install dbt-sqlserver | |
} | |
Function profileyaml { | |
New-Item -Path $env:USERPROFILE -Name .dbt -ItemType Directory | |
$profilefile | out-file -FilePath ($env:USERPROFILE + "\.dbt\profiles.yml") -Encoding ascii -Force | |
} | |
# need to add checks and error handling | |
InstallChoco | |
SetupVScode | |
profileyaml | |
ConfigPythonEnv | |
#Debug timer | |
#((get-date)- $starttime) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment