Skip to content

Commit feb49d9

Browse files
committed
Add Doltlite PHPUnit workflow
Run the mysql-on-sqlite PHPUnit suite against Doltlite commit 0745bbab by building it from source and installing its shared library as the libsqlite3 resolved by PHP's pdo_sqlite. Keep the remaining CI-only rowid compatibility patch in .github/doltlite-patches, with a focused runtime check before the full PHPUnit run.
1 parent 11cb7f2 commit feb49d9

2 files changed

Lines changed: 154 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Keep mysql-on-sqlite tables as rowid tables
2+
3+
Doltlite auto-converts ordinary primary-key tables without an integer rowid
4+
to WITHOUT ROWID. mysql-on-sqlite currently relies on rowid access for
5+
table recreation, limited UPDATE/DELETE rewrites, on-update triggers,
6+
zero-column result statements, and information-schema ordering. Keep the
7+
tables in rowid mode for the Doltlite compatibility test run.
8+
9+
--- a/src/build.c
10+
+++ b/src/build.c
11+
@@ -2794,5 +2794,5 @@ void sqlite3EndTable(
12+
&& (p->tabFlags & TF_HasPrimaryKey)!=0
13+
&& p->iPKey<0
14+
&& (tabOpts & TF_WithoutRowid)==0 ){
15+
- tabOpts |= TF_WithoutRowid;
16+
+ /* patched off in CI: keep mysql-on-sqlite tables as rowid tables */ (void)0;
17+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: PHPUnit Tests (Doltlite)
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
name: PHP ${{ matrix.php }} / Doltlite
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 30
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
php: [ '8.3' ]
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Install Doltlite build dependencies
26+
run: sudo apt-get update && sudo apt-get install -y build-essential zlib1g-dev tcl-dev
27+
28+
- name: Check out Doltlite
29+
uses: actions/checkout@v4
30+
with:
31+
repository: dolthub/doltlite
32+
ref: 0745bbab29778393780b220d2a91fc5fa753853f
33+
path: doltlite-src
34+
35+
- name: Patch Doltlite for mysql-on-sqlite compatibility
36+
# One narrow, verifiable source-level patch applied before build:
37+
# src/build.c — neutralize the auto-conversion of composite/TEXT-PK
38+
# tables to WITHOUT ROWID, since the driver currently relies on
39+
# rowid tables for table rewrites, DML rewrites, triggers, and
40+
# metadata reads.
41+
#
42+
# Doltlite upstream includes the other fixes needed by the full suite.
43+
run: |
44+
BUILD=doltlite-src/src/build.c
45+
46+
# Disable WITHOUT ROWID auto-conversion.
47+
patch -d doltlite-src -p1 --no-backup-if-mismatch \
48+
< .github/doltlite-patches/keep-driver-rowid-tables.patch
49+
50+
echo "--- Patched lines ---"
51+
grep -n 'keep mysql-on-sqlite tables as rowid tables' "$BUILD"
52+
53+
- name: Build Doltlite shared library
54+
run: |
55+
mkdir -p build
56+
cd build
57+
# Same feature set we enable for stock-SQLite runs. PHP's pdo_sqlite
58+
# pulls in sqlite3_column_table_name, which needs COLUMN_METADATA.
59+
CFLAGS="-DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_FTS5 -DSQLITE_USE_URI -DSQLITE_ENABLE_JSON1" \
60+
../configure
61+
make -j"$(nproc)" doltlite-lib
62+
ls -la libdoltlite* sqlite3.h
63+
working-directory: doltlite-src
64+
65+
- name: Set up PHP
66+
uses: shivammathur/setup-php@v2
67+
with:
68+
php-version: '${{ matrix.php }}'
69+
tools: phpunit-polyfills
70+
71+
- name: Install Doltlite as the system libsqlite3
72+
# Replace the system libsqlite3 the dynamic linker resolves for
73+
# pdo_sqlite with the Doltlite build. This is more reliable than
74+
# LD_PRELOAD, which loses to pdo_sqlite's DT_NEEDED on libsqlite3.so.0.
75+
run: |
76+
SRC="${GITHUB_WORKSPACE}/doltlite-src/build/libdoltlite.so"
77+
test -f "$SRC"
78+
79+
# Drop the build into /usr/local/lib and update the linker cache before
80+
# replacing the system libsqlite3 soname. Running ldconfig after the
81+
# replacement can restore Ubuntu's stock libsqlite3.so.0 symlink.
82+
sudo install -m 0755 "$SRC" /usr/local/lib/libdoltlite.so
83+
sudo ln -sf /usr/local/lib/libdoltlite.so /usr/local/lib/libdoltlite.so.0
84+
85+
sudo ldconfig
86+
87+
sudo ln -sf /usr/local/lib/libdoltlite.so /usr/local/lib/libsqlite3.so
88+
sudo ln -sf /usr/local/lib/libdoltlite.so /usr/local/lib/libsqlite3.so.0
89+
90+
MULTIARCH_DIR="$(dirname "$(readlink -f /lib/x86_64-linux-gnu/libsqlite3.so.0)")"
91+
sudo rm -f "${MULTIARCH_DIR}/libsqlite3.so.0"
92+
sudo ln -s /usr/local/lib/libdoltlite.so "${MULTIARCH_DIR}/libsqlite3.so.0"
93+
94+
echo "libsqlite3.so.0 target:"
95+
readlink -f /lib/x86_64-linux-gnu/libsqlite3.so.0
96+
97+
echo "ldd pdo_sqlite:"
98+
ldd "$(php -r 'echo ini_get("extension_dir");')/pdo_sqlite.so"
99+
100+
- name: Verify Doltlite is active and the rowid patch is applied
101+
run: |
102+
VERSION=$(php -r 'echo (new PDO("sqlite::memory:"))->query("SELECT SQLITE_VERSION()")->fetch()[0];')
103+
ENGINE=$(php -r 'echo (new PDO("sqlite::memory:"))->query("SELECT doltlite_engine()")->fetch()[0];')
104+
echo "SQLITE_VERSION() = ${VERSION}"
105+
echo "doltlite_engine() = ${ENGINE}"
106+
if [ "${ENGINE}" != "prolly" ]; then
107+
echo "::error::Doltlite is not active (expected doltlite_engine() = 'prolly', got '${ENGINE}')"
108+
exit 1
109+
fi
110+
STATS_ROWID=$(php -r '
111+
$db = new PDO("sqlite::memory:");
112+
$db->exec("CREATE TABLE _wp_sqlite_mysql_information_schema_statistics (table_schema TEXT, table_name TEXT, index_name TEXT, seq_in_index INT, PRIMARY KEY (table_schema, table_name, index_name, seq_in_index)) STRICT");
113+
$db->exec("INSERT INTO _wp_sqlite_mysql_information_schema_statistics VALUES (\"s\", \"t\", \"i\", 1)");
114+
echo $db->query("SELECT rowid FROM _wp_sqlite_mysql_information_schema_statistics")->fetch()[0];
115+
' 2>&1)
116+
echo "statistics metadata rowid = ${STATS_ROWID}"
117+
if ! [[ "${STATS_ROWID}" =~ ^[0-9]+$ ]]; then
118+
echo "::error::rowid-preservation patch did not take effect: ${STATS_ROWID}"
119+
exit 1
120+
fi
121+
122+
- name: Install Composer dependencies (root)
123+
uses: ramsey/composer-install@v3
124+
with:
125+
ignore-cache: "yes"
126+
composer-options: "--optimize-autoloader"
127+
128+
- name: Install Composer dependencies (mysql-on-sqlite)
129+
uses: ramsey/composer-install@v3
130+
with:
131+
working-directory: packages/mysql-on-sqlite
132+
ignore-cache: "yes"
133+
composer-options: "--optimize-autoloader"
134+
135+
- name: Run PHPUnit tests against Doltlite
136+
run: php ./vendor/bin/phpunit -c ./phpunit.xml.dist
137+
working-directory: packages/mysql-on-sqlite

0 commit comments

Comments
 (0)