Skip to content

Commit 84c2718

Browse files
committed
ivorysql compatible with documentdb
1 parent fdcbbe3 commit 84c2718

14 files changed

+104
-150
lines changed

.devcontainer/Dockerfile

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
FROM mcr.microsoft.com/mirror/docker/library/ubuntu:22.04
22
ARG POSTGRES_INSTALL_ARG=
3-
ARG PG_VERSION=16
3+
ARG IVORY_VERSION=4
44
ARG CITUS_VERSION=12
55

66
# declare installed PG version and Citus version
7-
ENV PG_VERSION=${PG_VERSION}
7+
ENV IVORY_VERSION=${IVORY_VERSION}
88
ENV CITUS_VERSION=${CITUS_VERSION}
99

1010
# Install build essentials - Compiler, debugger, make, etc.
@@ -35,6 +35,7 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
3535
libtool \
3636
libicu-dev \
3737
libssl-dev \
38+
libxml2-dev \
3839
&& rm -rf /var/lib/apt/lists/*
3940

4041
# Add pgdg repo
@@ -60,27 +61,27 @@ COPY scripts/utils.sh /tmp/install_setup/
6061

6162
# Install postgres
6263
COPY scripts/install_setup_postgres.sh /tmp/install_setup/
63-
RUN [ "bin/bash", "-c", "/tmp/install_setup/install_setup_postgres.sh -d \"/usr/lib/postgresql/${PG_VERSION}\" $POSTGRES_INSTALL_ARG -v ${PG_VERSION}" ]
64+
RUN [ "bin/bash", "-c", "/tmp/install_setup/install_setup_postgres.sh -d \"/var/local/ivorysql/ivory-${IVORY_VERSION}\" $POSTGRES_INSTALL_ARG -v ${IVORY_VERSION}" ]
6465

6566
# Install RUM from source
6667
COPY scripts/install_setup_rum_oss.sh /tmp/install_setup/
67-
RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_rum_oss.sh" ]
68+
RUN [ "bin/bash", "-c", "IVORYVERSION=$IVORY_VERSION /tmp/install_setup/install_setup_rum_oss.sh" ]
6869

6970
# Install citus
7071
COPY scripts/install_setup_citus_core_oss.sh /tmp/install_setup/
71-
RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_citus_core_oss.sh ${CITUS_VERSION}" ]
72+
RUN [ "bin/bash", "-c", "IVORYVERSION=$IVORY_VERSION /tmp/install_setup/install_setup_citus_core_oss.sh ${CITUS_VERSION}" ]
7273

7374
# Install citus-indent
7475
COPY scripts/install_citus_indent.sh /tmp/install_setup/
7576
RUN [ "bin/bash", "-c", "/tmp/install_setup/install_citus_indent.sh" ]
7677

7778
# Install SYSTEM_ROWS
7879
COPY scripts/install_setup_system_rows.sh /tmp/install_setup/
79-
RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_system_rows.sh" ]
80+
RUN [ "bin/bash", "-c", "IVORYVERSION=$IVORY_VERSION /tmp/install_setup/install_setup_system_rows.sh" ]
8081

8182
# Install PG_CRON
8283
COPY scripts/install_setup_pg_cron.sh /tmp/install_setup/
83-
RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_pg_cron.sh" ]
84+
RUN [ "bin/bash", "-c", "IVORYVERSION=$IVORY_VERSION /tmp/install_setup/install_setup_pg_cron.sh" ]
8485

8586
# Download Decimal128 Intel library
8687
COPY scripts/install_setup_intel_decimal_math_lib.sh /tmp/install_setup/
@@ -92,7 +93,7 @@ RUN [ "bin/bash", "-c", "/tmp/install_setup/install_setup_pcre2.sh" ]
9293

9394
# Install PG_VECTOR
9495
COPY scripts/install_setup_pgvector.sh /tmp/install_setup/
95-
RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_pgvector.sh" ]
96+
RUN [ "bin/bash", "-c", "IVORYVERSION=$IVORY_VERSION /tmp/install_setup/install_setup_pgvector.sh" ]
9697

9798
# Install PostGIS from source
9899
RUN apt-get update && \
@@ -105,7 +106,7 @@ RUN apt-get update && \
105106
&& rm -rf /var/lib/apt/lists/*
106107

107108
COPY scripts/install_setup_postgis.sh /tmp/install_setup/
108-
RUN [ "bin/bash", "-c", "PGVERSION=$PG_VERSION /tmp/install_setup/install_setup_postgis.sh" ]
109+
RUN [ "bin/bash", "-c", "IVORYVERSION=$IVORY_VERSION /tmp/install_setup/install_setup_postgis.sh" ]
109110

110111
# locale
111112
RUN rm -rf /var/lib/apt/lists/* \
@@ -121,10 +122,10 @@ RUN echo "%sudo ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers.d/no-pass-ask
121122

122123
# Add postgres to path for sudo commands.
123124
# Add path for sudoers
124-
RUN cat /etc/sudoers | grep secure_path | sed "s/\:\/bin\:/\:\/bin\:\/usr\/lib\/postgresql\/$PG_VERSION\/bin\:/" >> /etc/sudoers.d/postgres_path
125+
RUN cat /etc/sudoers | grep secure_path | sed "s/\:\/bin\:/\:\/bin\:\/var\/local\/ivorysql\/ivory-$IVORY_VERSION\/bin\:/" >> /etc/sudoers.d/postgres_path
125126

126127
# Add PG to the path
127-
ENV PATH=$PATH:/usr/lib/postgresql/$PG_VERSION/bin
128+
ENV PATH=$PATH:/var/local/ivorysql/ivory-$IVORY_VERSION/bin
128129

129130
USER documentdb
130131
WORKDIR /home/documentdb

README.md

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Introduction
22

3-
`DocumentDB` is the engine powering vCore-based Azure Cosmos DB for MongoDB. It offers a native implementation of document-oriented NoSQL database, enabling seamless CRUD operations on BSON data types within a PostgreSQL framework. Beyond basic operations, DocumentDB empowers you to execute complex workloads, including full-text searches, geospatial queries, and vector embeddings on your dataset, delivering robust functionality and flexibility for diverse data management needs.
3+
`ivydocumentdb` is an open-source project developed based on Microsoft DocumentDB and compatible with IvorySQL. It offers a native implementation of document-oriented NoSQL database, enabling seamless CRUD (Create, Read, Update, Delete) operations on BSON(Binary JSON) data types within an IvorySQL framework. Beyond basic operations, ivydocumentdb empowers you to execute complex workloads, including full-text searches, geospatial queries, and vector embeddings on your dataset, delivering robust functionality and flexibility for diverse data management needs.
4+
5+
[IvorySQL](https://docs.ivorysql.org/en/ivorysql-doc) is advanced, fully featured, open source Oracle compatible PostgreSQL with a firm commitment to always remain 100% compatible and a Drop-in replacement of the latest PostgreSQL.
46

57
[PostgreSQL](https://www.postgresql.org/about/) is a powerful, open source object-relational database system that uses and extends the SQL language combined with many features that safely store and scale the most complicated data workloads.
68

@@ -38,24 +40,24 @@ By building on PostgreSQL, DocumentDB leverages these strengths to provide a pow
3840

3941
### Building DocumentDB with Docker
4042

41-
Step 1: Clone the DocumentDB repo.
43+
Step 1: Clone the ivydocumentdb repo.
4244

4345
```bash
44-
git clone https://github.com/microsoft/documentdb.git
46+
git clone https://github.com/ivorysql/ivydocumentdb.git
4547
```
4648

4749
Step 2: Create the docker image. Navigate to cloned repo.
4850

4951
```bash
50-
docker build . -f .devcontainer/Dockerfile -t documentdb
52+
docker build . -f .devcontainer/Dockerfile -t ivydocumentdb
5153
```
5254

5355
Note: Validate using `docker image ls`
5456

5557
Step 3: Run the Image as a container
5658

5759
```bash
58-
docker run -v $(pwd):/home/documentdb/code -it documentdb /bin/bash
60+
docker run -v $(pwd):/home/documentdb/code -it ivydocumentdb /bin/bash
5961

6062
cd code
6163
```
@@ -79,36 +81,6 @@ Note: To run backend postgresql tests after installing you can run `make check`.
7981

8082
You are all set to work with DocumentDB.
8183

82-
### Using the Prebuilt Docker Image
83-
84-
You can use a [prebuilt docker image](https://github.com/microsoft/documentdb/pkgs/container/documentdb%2Fdocumentdb-oss/versions?filters%5Bversion_type%5D=tagged) for DocumentDB instead of building it from source. Follow these steps:
85-
86-
#### Pull the Prebuilt Image
87-
88-
Pull the prebuilt image directly from the Microsoft Container Registry:
89-
90-
```bash
91-
docker pull ghcr.io/microsoft/documentdb/documentdb-oss:PG16-amd64-0.105.0
92-
```
93-
94-
#### Running the Prebuilt Image
95-
96-
To run the prebuilt image, use one of the following commands:
97-
98-
1. Run the container:
99-
100-
```bash
101-
docker run -dt ghcr.io/microsoft/documentdb/documentdb-oss:PG16-amd64-0.105.0
102-
```
103-
104-
2. If external access is required, run the container with parameter "-e":
105-
106-
```bash
107-
docker run -p 127.0.0.1:9712:9712 -dt ghcr.io/microsoft/documentdb/documentdb-oss:PG16-amd64-0.105.0 -e
108-
```
109-
110-
This will start the container and map port `9712` from the container to the host.
111-
11284
### Connecting to the Server
11385
#### Internal Access
11486
Step 1: Run `start_oss_server.sh` to initialize the DocumentDB server and manage dependencies.
@@ -297,16 +269,3 @@ The example presents each patient along with the doctors visited.
297269
```sql
298270
SELECT cursorpage FROM documentdb_api.aggregate_cursor_first_page('documentdb', '{ "aggregate": "patient", "pipeline": [ { "$lookup": { "from": "appointment","localField": "patient_id", "foreignField": "patient_id", "as": "appointment" } },{"$unwind":"$appointment"},{"$project":{"_id":0,"name":1,"appointment.doctor_name":1,"appointment.appointment_date":1}} ], "cursor": { "batchSize": 3 } }');
299271
```
300-
301-
### Community
302-
303-
- Please refer to page for contributing to our [Roadmap list](https://github.com/orgs/microsoft/projects/1407/views/1).
304-
- [FerretDB](https://github.com/FerretDB/FerretDB) integration allows using DocumentDB as backend engine.
305-
306-
Contributors and users can join the [DocumentDB Discord channel in the Microsoft OSS server](https://aka.ms/documentdb_discord) for quick collaboration.
307-
308-
### FAQs
309-
310-
Q1. While performing `make check` if you encounter error `FATAL: "/home/documentdb/code/pg_documentdb_core/src/test/regress/tmp/data" has wrong ownership`?
311-
312-
Please drop the `/home/documentdb/code/pg_documentdb_core/src/test/regress/tmp/` directory and rerun the `make check`.

scripts/build_and_start_gateway.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,21 @@ while [[ -L $source ]]; do
8484
done
8585
scriptDir="$(cd -P "$(dirname "$source")" && pwd)"
8686

87-
# Check if PostgreSQL is running with a timeout of 10 minutes
87+
# Check if IvorySQL is running with a timeout of 10 minutes
8888
timeout=600
8989
interval=5
9090
elapsed=0
9191

92-
echo "Waiting for PostgreSQL to be ready on $hostname:$port..."
92+
echo "Waiting for IvorySQL to be ready on $hostname:$port..."
9393
while ! pg_isready -h "$hostname" -p "$port" > /dev/null 2>&1; do
9494
if [ "$elapsed" -ge "$timeout" ]; then
95-
echo "PostgreSQL did not become ready within 10 minutes. Exiting."
95+
echo "IvorySQL did not become ready within 10 minutes. Exiting."
9696
exit 1
9797
fi
9898
sleep "$interval"
9999
elapsed=$((elapsed + interval))
100100
done
101-
echo "PostgreSQL is ready."
101+
echo "IvorySQL is ready."
102102

103103
if [ "$clean" = "true" ]; then
104104
echo "Cleaning the build directory..."

scripts/generate_extension_version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if [ -f $gitIndexDir ]; then
3333
else
3434
# set GIT_VERSION with current branch's name and the short sha of the HEAD
3535
GIT_VERSION=$(git rev-parse --abbrev-ref HEAD)
36-
GIT_SHA=$(git rev-parse --short HEAD)
36+
GIT_SHA=$(git rev-parse --short=10 HEAD)
3737
fi
3838

3939
if [[ "$GIT_VERSION" == "" ]] || [[ "$GIT_SHA" == "" ]]; then

scripts/install_setup_citus_core_oss.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ scriptDir="$( cd -P "$( dirname "$source" )" && pwd )"
2222
CITUS_REF=$(GetCitusVersion $citusVersion)
2323

2424
. $scriptDir/utils.sh
25-
if [ "${PGVERSION:-}" != "" ]; then
26-
pgPath=$(GetPostgresPath $PGVERSION)
25+
if [ "${IVORYVERSION:-}" != "" ]; then
26+
pgPath=$(GetPostgresPath $IVORYVERSION)
2727
PATH=$pgPath:$PATH
2828
fi
2929

scripts/install_setup_pg_cron.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ scriptDir="$( cd -P "$( dirname "$source" )" && pwd )"
2020
CITUS_PG_CRON_REF=$(GetPgCronVersion)
2121

2222
. $scriptDir/utils.sh
23-
pgBinDir=$(GetPostgresPath $PGVERSION)
23+
pgBinDir=$(GetPostgresPath $IVORYVERSION)
2424
PATH=$pgBinDir:$PATH;
2525

2626
pushd $INSTALL_DEPENDENCIES_ROOT

scripts/install_setup_pgvector.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ scriptDir="$( cd -P "$( dirname "$source" )" && pwd )"
1818
echo "scriptDir: $scriptDir"
1919

2020
. $scriptDir/utils.sh
21-
pgBinDir=$(GetPostgresPath $PGVERSION)
21+
pgBinDir=$(GetPostgresPath $IVORYVERSION)
2222
PATH=$pgBinDir:$PATH;
2323

2424
. $scriptDir/setup_versions.sh

scripts/install_setup_postgis.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ scriptDir="$( cd -P "$( dirname "$source" )" && pwd )"
2727
POSTGIS_REF=$(GetPostgisVersion)
2828

2929
. $scriptDir/utils.sh
30-
pgBinDir=$(GetPostgresPath $PGVERSION)
30+
pgBinDir=$(GetPostgresPath $IVORYVERSION)
3131

3232
POSTGIS_REPO=postgis-repo
3333
rm -rf $POSTGIS_REPO

scripts/install_setup_postgres.sh

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ set -e
55
# fail if trying to reference a variable that is not set.
66
set -u
77

8-
postgresqlInstallDir=""
8+
ivorysqlInstallDir=""
99
debug="false"
1010
cassert="false"
1111
help="false";
12-
pgVersion=""
12+
ivyVersion=""
1313
while getopts "d:hxcv:" opt; do
1414
case $opt in
15-
d) postgresqlInstallDir="$OPTARG"
15+
d) ivorysqlInstallDir="$OPTARG"
1616
;;
1717
x) debug="true"
1818
;;
1919
c) cassert="true"
2020
;;
2121
h) help="true"
2222
;;
23-
v) pgVersion="$OPTARG"
23+
v) ivyVersion="$OPTARG"
2424
;;
2525
esac
2626

@@ -34,18 +34,18 @@ while getopts "d:hxcv:" opt; do
3434
done
3535

3636
if [ "$help" == "true" ]; then
37-
echo "downloads postgresql-14.2 sources, build and install it."
38-
echo "[-d] the directory to install postgresql to. Default: /usr/lib/postgresql/14"
37+
echo "downloads IvorySQL-14.2 sources, build and install it."
38+
echo "[-d] the directory to install IvorySQL to. Default: /usr/lib/IvorySQL/14"
3939
echo "[-x] build with debug symbols."
4040
exit 1;
4141
fi
4242

43-
if [ -z $postgresqlInstallDir ]; then
43+
if [ -z $ivorysqlInstallDir ]; then
4444
echo "Postgres Install Directory must be specified."
4545
exit 1;
4646
fi
4747

48-
if [ -z $pgVersion ]; then
48+
if [ -z $ivyVersion ]; then
4949
echo "PG Version must be specified";
5050
exit 1;
5151
fi
@@ -62,29 +62,29 @@ done
6262
scriptDir="$( cd -P "$( dirname "$source" )" && pwd )"
6363

6464
. $scriptDir/setup_versions.sh
65-
POSTGRESQL_REF=$(GetPostgresSourceRef $pgVersion)
65+
IvorySQL_REF=$(GetPostgresSourceRef $ivyVersion)
6666

6767
pushd $INSTALL_DEPENDENCIES_ROOT
6868

69-
rm -rf postgres-repo/$pgVersion
70-
mkdir -p postgres-repo/$pgVersion
71-
cd postgres-repo/$pgVersion
69+
rm -rf postgres-repo/$ivyVersion
70+
mkdir -p postgres-repo/$ivyVersion
71+
cd postgres-repo/$ivyVersion
7272

7373
git init
74-
git remote add origin https://github.com/postgres/postgres
74+
git remote add origin https://github.com/IvorySQL/IvorySQL
7575

7676
# checkout to the commit specified in the cgmanifest.json
77-
git fetch --depth 1 origin "$POSTGRESQL_REF"
77+
git fetch --depth 1 origin "$IvorySQL_REF"
7878
git checkout FETCH_HEAD
7979

80-
echo "building and installing postgresql ref $POSTGRESQL_REF and installing to $postgresqlInstallDir..."
80+
echo "building and installing IvorySQL ref $IvorySQL_REF and installing to $ivorysqlInstallDir..."
8181

8282
if [ "$debug" == "true" ]; then
83-
./configure --enable-debug --enable-cassert --enable-tap-tests CFLAGS="-ggdb -Og -g3 -fno-omit-frame-pointer" --with-openssl --prefix="$postgresqlInstallDir" --with-icu
83+
./configure --enable-debug --enable-cassert --enable-tap-tests CFLAGS="-ggdb -Og -g3 -fno-omit-frame-pointer" --with-openssl --prefix="$ivorysqlInstallDir" --with-icu
8484
elif [ "$cassert" == "true" ]; then
85-
./configure --enable-debug --enable-cassert --enable-tap-tests --with-openssl --prefix="$postgresqlInstallDir" --with-icu
85+
./configure --enable-debug --enable-cassert --enable-tap-tests --with-openssl --prefix="$ivorysqlInstallDir" --with-icu
8686
else
87-
./configure --enable-debug --enable-tap-tests --with-openssl --prefix="$postgresqlInstallDir" --with-icu
87+
./configure --enable-debug --enable-tap-tests --with-openssl --prefix="$ivorysqlInstallDir" --with-icu
8888
fi
8989

9090
make clean && make -sj$(cat /proc/cpuinfo | grep -c "processor") install

scripts/install_setup_rum_oss.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ echo "scriptDir: $scriptDir"
2121
RUM_REF=$(GetRumVersion)
2222

2323
. $scriptDir/utils.sh
24-
if [ "${PGVERSION:-}" != "" ]; then
25-
pgPath=$(GetPostgresPath $PGVERSION)
24+
if [ "${IVORYVERSION:-}" != "" ]; then
25+
pgPath=$(GetPostgresPath $IVORYVERSION)
2626
PATH=$pgPath:$PATH
2727
fi
2828

0 commit comments

Comments
 (0)