Open agent-app-kapeltol[bot] opened 3 months ago
Here's an example of a bash script that you could use to create an Azure SQL Database and deploy a database schema to it. You need to replace the placeholders <...>
with your actual values.
#!/bin/bash
# Set variables
resourceGroup="<resource-group>"
location="<location>"
serverName="<server-name>"
adminUser="<admin-user>"
password="<password>"
databaseName="<database-name>"
schemaFilePath="<schema-file-path>"
# Create a resource group
az group create --name $resourceGroup --location $location
# Create a SQL Server
az sql server create --name $serverName --resource-group $resourceGroup --location $location --admin-user $adminUser --admin-password $password
# Create a database in the server
az sql db create --name $databaseName --resource-group $resourceGroup --server $serverName --service-objective S0
# Create a firewall rule to allow access from Azure services
az sql server firewall-rule create --resource-group $resourceGroup --server $serverName -n AllowAzure --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
# Deploy the schema using sqlcmd utility
sqlcmd -S tcp:$serverName.database.windows.net,1433 -d $databaseName -U $adminUser -P $password -i $schemaFilePath
Here are a few things to note:
az group create
command creates a new resource group.az sql server create
command creates a new Azure SQL Server.az sql db create
command creates a new database in the SQL Server.az sql server firewall-rule create
command creates a firewall rule that allows access to the server from Azure services.sqlcmd
utility is used to deploy the schema from a .sql file. This utility must be installed on your machine.<resource-group>
, <location>
, <server-name>
, <admin-user>
, <password>
, <database-name>
, and <schema-file-path>
with your respective values.
Write the Azure CLI script to create an Azure SQL Database and deploy the database schema to it.