-
Notifications
You must be signed in to change notification settings - Fork 22
LPD-62912 Add support for Microsoft SQL Server 2022 #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
6893818
LPD-62912 Add configs for SQL Server
anthony-chu 441b2c9
LPD-62912 Include SQL Server JDBC jar in bundle
anthony-chu 3f76e26
LPD-62912 Reuse DB2 database results for SQL Server
anthony-chu 020f54d
LPD-62912 Add recipe files for SQL Server
anthony-chu 730a4f4
LPD-62912 Optionally change ownership for SQL Server files in data-he…
anthony-chu bd54b02
LPD-62912 Expose property for SQL Server
anthony-chu 9829c00
LPD-62912 Update README
anthony-chu 1fe39ac
LPD-62912 Copy as root
anthony-chu 9473df8
LPD-62912 Using busybox is sufficient
anthony-chu 6b87728
LPD-62912 Convert to elif statements
anthony-chu 1bf9e94
LPD-62912 Add restore to entrypoint
anthony-chu 531744d
LPD-62912 Update condition
anthony-chu 4f8a859
LPD-62912 Add config for database type
anthony-chu c73b844
LPD-62912 Consolidate jdbc driver tasks into one
anthony-chu f196aea
LPD-62912 Add missing MariaDB config for consistency
anthony-chu 630271b
LPD-62912 Run copy task conditionally
anthony-chu f6ce535
LPD-62912 Add mssql jdbc jar to .gitignore
anthony-chu c1c5f01
LPD-62912 uses the configuration itself to conditionally run the task
drewbrokke 53a0b8f
LPD-62912 Ensure dump is owned by mssql user when using SQL Server
anthony-chu 4b2d942
LPD-62912 Ensure column name is single quoted to avoid keyword
anthony-chu e631132
LPD-62912 Include backup file for sql server
anthony-chu 44dbd38
LPD-62912 Fix backup file path
anthony-chu 467a68b
LPD-62912 Return empty map if no results are found
anthony-chu 54254f6
LPD-62912 Fix database file location
anthony-chu d2e5d00
LPD-62912 Fix health check
anthony-chu 70538d9
LPD-62912 Use early returns
anthony-chu 7ae54a9
LPD-62912 Make entrypoint echos clearer
anthony-chu 1736a2d
LPD-62912 Fix DB type
anthony-chu cdd3244
LPD-62912 Field not used
anthony-chu 121e76c
LPD-62912 Add missing documentation
anthony-chu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM mcr.microsoft.com/mssql/server:2022-CU21-ubuntu-22.04 | ||
|
||
USER root | ||
|
||
RUN mkdir -p /var/opt/mssql/backups /var/opt/mssql/data | ||
RUN chown -R mssql:mssql /var/opt/mssql/ | ||
RUN touch /startup_log.txt | ||
RUN chown mssql:mssql /startup_log.txt | ||
|
||
COPY entrypoint.sh /init/ | ||
COPY init.sql /init/ | ||
COPY reinit.sql /init | ||
COPY restore.sql /init | ||
|
||
RUN chown -R mssql:mssql /init && \ | ||
chmod a+x /init/entrypoint.sh | ||
|
||
USER mssql | ||
|
||
ENTRYPOINT ["/bin/bash", "/init/entrypoint.sh"] |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
services: | ||
liferay-cluster-node: | ||
environment: | ||
- LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_DRIVER_UPPERCASEC_LASS_UPPERCASEN_AME=com.microsoft.sqlserver.jdbc.SQLServerDriver | ||
- LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_PASSWORD=Liferay123 | ||
- LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_URL=jdbc:sqlserver://database:1433;databaseName=lportal;Encrypt=True;TrustServerCertificate=True | ||
- LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_USERNAME=sa |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
|
||
_sqlcmd="/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P ${MSSQL_SA_PASSWORD}" | ||
|
||
_has_backup_file() { | ||
if [[ $(find /var/opt/mssql/backups -type f -iname "*.bak") ]]; then | ||
echo true | ||
fi | ||
} | ||
|
||
_has_database_files() { | ||
local database_name=${1} | ||
|
||
if [[ $(find /var/opt/mssql/data -type f -iname "${database_name}.*") ]]; then | ||
echo true | ||
fi | ||
} | ||
|
||
_is_database_present() { | ||
local database_name=${1} | ||
|
||
if [[ $(${_sqlcmd} -Q "select name from sys.databases" | grep "${database_name}") ]]; then | ||
|
||
echo true | ||
fi | ||
} | ||
|
||
create_database() { | ||
local database_name=${1} | ||
|
||
if [[ $(_is_database_present ${database_name}) ]]; then | ||
echo "[entrypoint] Database ${database_name} is present; skipping database creation" | ||
|
||
return | ||
fi | ||
|
||
if [[ $(_has_backup_file) ]]; then | ||
echo "[entrypoint] Database backup found; restoring database ${database_name}..." | ||
|
||
sed -i "s,%DATABASE_NAME%,${database_name},g" /init/restore.sql | ||
|
||
local backup_file=$(find /var/opt/mssql/backups -type f -iname "*.bak") | ||
|
||
sed -i "s,%BACKUP_FILE%,${backup_file},g" /init/restore.sql | ||
|
||
${_sqlcmd} -i /init/restore.sql | ||
|
||
return | ||
fi | ||
|
||
if [[ $(_has_database_files ${database_name}) ]]; then | ||
echo "Database files found; reattaching database ${database_name}..." | ||
|
||
sed -i "s,%DATABASE_NAME%,${database_name},g" /init/reinit.sql | ||
|
||
${_sqlcmd} -i /init/reinit.sql | ||
|
||
return | ||
fi | ||
|
||
echo "[entrypoint] Could not find database ${database_name}; creating database..." | ||
|
||
sed -i "s,%DATABASE_NAME%,${database_name},g" /init/init.sql | ||
|
||
${_sqlcmd} -i /init/init.sql | ||
drewbrokke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
main() { | ||
until ${_sqlcmd} -Q "SELECT 1"; do | ||
sleep 1 | ||
echo "[entrypoint] Waiting for SQL Server to be available..." | ||
done | ||
|
||
create_database ${COMPOSER_DATABASE_NAME} | ||
} | ||
|
||
main & /opt/mssql/bin/sqlservr | ||
|
||
wait |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CREATE DATABASE %DATABASE_NAME% | ||
GO |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
services: | ||
liferay: | ||
depends_on: | ||
database: | ||
condition: service_healthy | ||
environment: | ||
- LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_DRIVER_UPPERCASEC_LASS_UPPERCASEN_AME=com.microsoft.sqlserver.jdbc.SQLServerDriver | ||
- LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_PASSWORD=Liferay123 | ||
- LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_URL=jdbc:sqlserver://database:1433;databaseName=lportal;Encrypt=True;TrustServerCertificate=True | ||
- LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_USERNAME=sa |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this issue observed? Is this backwards compatible with other database types?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initially, it gives a unhelpful exception:
this comes from the attempt to parse the results of the executed sql query. printing out the actual bare result that comes back from the query, the following response is given:
for SQL Server,
false
is a reserved keyword. in order to be used as a string, it needs to be quoted.i had not tested it for other databases. i did just now, and other databases don't accept the single-quotes around
false
, so added a check for the database to determine which sql statement to use.i'll send a follow-up PR to address the other DBs.