Как сказано в вопросе, как мне это сделать? Это сценарий, который я сейчас использую для создания файла .dacpac, но я видел, что это можно сделать с помощью сценария PowerShell вместо AzureCLI@2?
Я попробовал этот скрипт AzureCLI@2:
- task: AzureCLI@2
inputs:
azureSubscription: '$(azureSubscription)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
set -e
echo "Starting DACPAC extraction..."
# Obtain an access token
echo "Obtaining access token..."
accessToken=$(az account get-access-token --resource https://database.windows.net/ --query accessToken --output tsv)
echo "Access token obtained."
# Check if the access token was retrieved
if [ -z "$accessToken" ]; then
echo "Failed to obtain access token. Exiting."
exit 1
fi
# Create directories if they don't exist
mkdir -p $(Build.SourcesDirectory)/temp/DACPAC
mkdir -p $(Build.SourcesDirectory)/some/ran/dir/
# Extract DACPAC file to a temporary directory
echo "Extracting DACPAC file..."
./sqlpackage/sqlpackage /Action:Extract /SourceServerName:$(sqlServerName) /SourceDatabaseName:$(sqlDatabaseName) /TargetFile:$(Build.SourcesDirectory)/temp/DACPAC/$(sqlDatabaseName).dacpac /AccessToken:$accessToken
# Unzip the extracted DACPAC file
echo "Unzipping DACPAC file..."
unzip -o $(Build.SourcesDirectory)/temp/DACPAC/$(sqlDatabaseName).dacpac -d $(Build.SourcesDirectory)/temp/DACPAC
# Move extracted schema files to the target directory, replacing existing files
echo "Replacing existing .sql files with updated schema..."
find $(Build.SourcesDirectory)/temp/DACPAC -name '*.sql' -exec cp -v {} $(Build.SourcesDirectory)/some/ran/dir/ \; 2>error.log
echo "Schema extraction and replacement completed."
echo "Listing files in target directory..."
ls -l $(Build.SourcesDirectory)/some/ran/dir/
ls -l $(Build.SourcesDirectory)/temp/DACPAC
# Commit and push the changes
echo "Committing and pushing changes..."
cd $(Build.SourcesDirectory)
git config --global user.email "$(sqlAdminLogin)"
git config --global user.name "Name"
git add --all
git status
git commit -m "Update schema files from DACPAC extraction" || echo "No changes to commit"
git push https://$(azureDevOpsPat)@dev.azure.com ... /repo/here HEAD:$(Build.SourceBranch) --force
ls -l $(Build.SourcesDirectory)/some/ran/dir/
echo "Changes committed and pushed."
Я ожидал, что файлы будут перенесены в указанное место, но там просто написано: «Отдельная голова». Попытка изменить ветку репо с помощью проверки и создания временной ветки также не работает.
Обновление № 1
Вот что показывает мой конвейер для вышеупомянутой задачи:
HEAD detached at fc510bf
nothing to commit, working tree clean
HEAD detached at fc510bf
nothing to commit, working tree clean
No changes to commit
Everything up-to-date
Однако каждый скрипт отображается в следующем каталоге:
-rw-r--r-- 1 vsts docker 995 Jul 24 06:42 Surgeons.sql
Обновление № 2
Следующий путь работает, но я добавил его в свой .gitignore как Я хочу использовать только сценарии .sql для каждой таблицы:
$(Build.SourcesDirectory)/temp/DACPAC
Обновление №3
Скрипт извлекает этот скрипт:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Contact Report](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Report Date] [datetime] NOT NULL,
[Report Description] [text] NOT NULL,
[Customer ID] [varchar](50) NOT NULL,
[Location] [varchar](100) NOT NULL,
[Follow Up] [varchar](100) NOT NULL,
[Feedback] [text] NOT NULL,
[Notes] [text] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[Contact Report] ADD PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
Но он должен вытащить этот сценарий (как используется в фабрике данных Azure):
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Contact Report](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Report Date] [datetime] NOT NULL,
[Report Description] [text] NOT NULL,
[Customer ID] [varchar](50) NOT NULL,
[Location] [varchar](100) NOT NULL,
[Follow Up] [varchar](100) NOT NULL,
[Feedback] [text] NOT NULL,
[Notes] [text] NOT NULL,
[Staff ID] [varchar](10) NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[Contact Report] ADD PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Contact Report] WITH CHECK ADD CONSTRAINT [FK_ContactReport_Staff] FOREIGN KEY([Staff ID])
REFERENCES [dbo].[Staff] ([Staff ID])
GO
ALTER TABLE [dbo].[Contact Report] CHECK CONSTRAINT [FK_ContactReport_Staff]
GO
Подробнее здесь: https://stackoverflow.com/questions/787 ... abase-in-m
Я не могу извлечь таблицы .sql CREATE TABLE для каждой таблицы в базе данных SQL Azure в репозитории Azure. ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Укладка элементов div по вертикали при использовании display:table, table-row, table-cell
Anonymous » » в форуме CSS - 0 Ответы
- 124 Просмотры
-
Последнее сообщение Anonymous
-