mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
### Object of this PR This PR is NOT a monolithic series of fixes for the payments suite + a complete rework. Its aims were a) introducing and robustly testing the bulldozer db system b) reworking the payments underlying architecture to use bulldozer for correctness and scalability c) Achieving parity with the old payments system excepting a few changes like ensuring correctness of the ledger algo There may still be some work to do with handling refunds, decoupling the concepts of purchases from that of products, and some other things. ### Ledger Algorithm This has been tuned and fixed. Item removals i.e negative item quantity changes will apply to the soonest expiring item grant i.e positive item quantity change. This is what is best for the user. Item grants can also expire, and when they expire we obviate whatever is left of their original capacity (meaning after all the removals that were applied to it). Our ledger algo is applied via Bulldozer, so automatic re-computation is handled when a new grant/ removal is inserted in the middle of the existing ones. ### Things we got rid of * No more automatic support for default products. You can use $0 plan provisions to accomplish the same effect but it's manual * Negative item quantity changes (i.e item removals) no longer can have expiries <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Enhanced payment processing pipeline with improved data consistency and state management. * Advanced refund handling with comprehensive transaction tracking. * Better tracking and management of customer item quantities and owned products. * Improved subscription lifecycle management including period-end handling. * **Bug Fixes** * Fixed payment data integrity verification. * Improved handling of edge cases in refund scenarios. * **Chores** * Updated cSpell configuration with additional words. * Expanded developer documentation for linting workflows. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Konstantin Wohlwend <n2d4xc@gmail.com> Co-authored-by: Aadesh Kheria <kheriaaadesh@gmail.com> Co-authored-by: Mantra <87142457+mantrakp04@users.noreply.github.com>
66 lines
3.1 KiB
Docker
66 lines
3.1 KiB
Docker
FROM postgres:15
|
|
|
|
RUN apt-get update && apt-get install -y \
|
|
git \
|
|
build-essential \
|
|
libpq-dev \
|
|
postgresql-server-dev-15 \
|
|
postgresql-15-cron
|
|
|
|
# Install HypoPG
|
|
RUN git clone https://github.com/HypoPG/hypopg.git /hypopg
|
|
RUN cd /hypopg && make install
|
|
|
|
# Install index_advisor
|
|
RUN git clone https://github.com/supabase/index_advisor.git /index_advisor
|
|
RUN cd /index_advisor && make install
|
|
|
|
# Write initialization SQL
|
|
RUN echo "CREATE EXTENSION pg_stat_statements;" >> /docker-entrypoint-initdb.d/init.sql
|
|
RUN echo "CREATE EXTENSION pg_cron;" >> /docker-entrypoint-initdb.d/init.sql
|
|
RUN echo "CREATE EXTENSION hypopg;" >> /docker-entrypoint-initdb.d/init.sql
|
|
RUN echo "CREATE EXTENSION index_advisor;" >> /docker-entrypoint-initdb.d/init.sql
|
|
RUN echo "CREATE ROLE anon;" >> /docker-entrypoint-initdb.d/init.sql
|
|
RUN echo "CREATE ROLE authenticated;" >> /docker-entrypoint-initdb.d/init.sql
|
|
|
|
# Create a read-only user for read replica emulation in development
|
|
RUN echo "CREATE USER readonly WITH PASSWORD 'PASSWORD-PLACEHOLDER--readonlyuqfEC1hmmv';" >> /docker-entrypoint-initdb.d/init.sql
|
|
RUN echo "GRANT CONNECT ON DATABASE stackframe TO readonly;" >> /docker-entrypoint-initdb.d/init.sql
|
|
RUN echo "GRANT USAGE ON SCHEMA public TO readonly;" >> /docker-entrypoint-initdb.d/init.sql
|
|
RUN echo "GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;" >> /docker-entrypoint-initdb.d/init.sql
|
|
RUN echo "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly;" >> /docker-entrypoint-initdb.d/init.sql
|
|
|
|
# Create a replication user for streaming replication to the replica
|
|
RUN echo "CREATE USER replicator WITH REPLICATION PASSWORD 'PASSWORD-PLACEHOLDER--replicatorpass';" >> /docker-entrypoint-initdb.d/init.sql
|
|
|
|
# Create a script to add replication permissions to pg_hba.conf after init
|
|
# This script runs after the database is initialized but before it starts accepting connections
|
|
RUN echo '#!/bin/bash' > /docker-entrypoint-initdb.d/00-setup-replication.sh && \
|
|
echo 'echo "host replication replicator all scram-sha-256" >> "$PGDATA/pg_hba.conf"' >> /docker-entrypoint-initdb.d/00-setup-replication.sh && \
|
|
chmod +x /docker-entrypoint-initdb.d/00-setup-replication.sh
|
|
|
|
# Add args to Postgres entrypoint
|
|
ENTRYPOINT ["sh", "-c", "\
|
|
# Add delay if POSTGRES_DELAY_MS is set \
|
|
if [ $POSTGRES_DELAY_MS -gt 0 ]; then \
|
|
apt-get update && apt-get install -y iproute2 && tc qdisc add dev eth0 root netem delay ${POSTGRES_DELAY_MS}ms; \
|
|
fi; \
|
|
\
|
|
# Start Postgres with replication enabled and extensions \
|
|
exec docker-entrypoint.sh postgres \
|
|
-c shared_preload_libraries='pg_stat_statements,pg_cron' \
|
|
-c cron.database_name='stackframe' \
|
|
-c pg_stat_statements.track=all \
|
|
-c logging_collector=on \
|
|
-c log_destination='stderr' \
|
|
-c log_min_messages=log \
|
|
-c log_directory='log' \
|
|
-c log_filename='postgresql-%Y-%m-%d_%H%M%S.log' \
|
|
-c wal_level=logical \
|
|
-c max_wal_senders=5 \
|
|
-c max_replication_slots=5 \
|
|
-c wal_keep_size=64MB \
|
|
-c hot_standby=on \
|
|
-c statement_timeout=30s `# In production this is higher, but better safe than sorry during dev` \
|
|
"]
|