Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/resources/reports/calendar-postgresql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
drop procedure if exists create_calendar;

create procedure create_calendar(calendar_from date, calendar_to date)
language plpgsql as $$
declare
d date;
begin
d := calendar_from;
drop table if exists calendar;
create table calendar(d date primary key);
while d <= calendar_to loop
insert into calendar(d) values (d);
d := d + interval '1 day';
end loop;
end
$$;

call create_calendar((now() - interval '5 years')::date, (now() + interval '10 years')::date);
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
drop table if exists report_conversions_total_dollar_monthly;
create table report_conversions_total_dollar_monthly (tenant_record_id int(11), day date, term varchar(50), count int(10));
create table report_conversions_total_dollar_monthly (tenant_record_id int, day date, term varchar(50), count int);
53 changes: 50 additions & 3 deletions src/main/resources/seed_reports.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,32 @@ KILLBILL_PASSWORD=${KILLBILL_PASSWORD-"password"}
KILLBILL_API_KEY=${KILLBILL_API_KEY-"bob"}
KILLBILL_API_SECRET=${KILLBILL_API_SECRET-"lazar"}

DATABASE_TYPE=${DATABASE_TYPE-"mysql"} # can be mysql or postgresql

MYSQL_HOST=${MYSQL_HOST-"127.0.0.1"}
MYSQL_USER=${MYSQL_USER-"root"}
MYSQL_PASSWORD=${MYSQL_PASSWORD-"root"}
MYSQL_DATABASE=${MYSQL_DATABASE-"killbill"}

POSTGRES_HOST=${POSTGRES_HOST-"127.0.0.1"}
POSTGRES_PORT=${POSTGRES_PORT-"5432"}
POSTGRES_USER=${POSTGRES_USER-"killbill"}
POSTGRES_PASSWORD=${POSTGRES_PASSWORD-"killbill"}
POSTGRES_DATABASE=${POSTGRES_DATABASE-"killbill"}

REPORTS=$HERE/reports
SYSTEM=$HERE/system

function install_ddl() {
local ddl=$1
mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE -e "source $ddl"
if [[ $DATABASE_TYPE == "postgresql" ]]; then
# check if pg ddl file exists
local pg_ddl="${ddl%.*}-postgresql.${ddl##*.}"
if [ -f $pg_ddl ]; then ddl=$pg_ddl; fi
PGPASSWORD=$POSTGRES_PASSWORD psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER $POSTGRES_DATABASE -f $ddl
else
mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE -e "source $ddl"
fi
}

function create_report() {
Expand All @@ -64,28 +79,60 @@ function create_report() {

# Install the DDL - the calendar table needs to be first
install_ddl $REPORTS/calendar.sql
for r in `find $REPORTS -type f -name '*.sql' -o -name '*.ddl' -maxdepth 1`; do install_ddl $r; done
for r in `find $SYSTEM -type f -name '*.sql' -o -name '*.ddl' -maxdepth 1`; do install_ddl $r; done

# Dashboard views
install_ddl $REPORTS/accounts_summary/v_report_accounts_summary.ddl
create_report 'accounts_summary' 'Account summary' 'COUNTERS' 'v_report_accounts_summary'

install_ddl $REPORTS/active_by_product_term_monthly/v_report_active_by_product_term_monthly.ddl
create_report 'active_by_product_term_monthly' 'Active subscriptions' 'TIMELINE' 'v_report_active_by_product_term_monthly'

install_ddl $REPORTS/cancellations_daily/v_report_cancellations_daily.ddl
create_report 'cancellations_count_daily' 'Cancellations' 'TIMELINE' 'v_report_cancellations_daily'

install_ddl $REPORTS/chargebacks_daily/v_report_chargebacks_daily.ddl
create_report 'chargebacks_daily' 'Chargebacks' 'TIMELINE' 'v_report_chargebacks_daily'

install_ddl $REPORTS/v_report_conversions_daily.ddl
create_report 'conversions_daily' 'Conversions' 'TIMELINE' 'v_report_conversions_daily'

install_ddl $REPORTS/v_report_invoice_adjustments_daily.ddl
create_report 'invoice_adjustments_daily' 'Invoice adjustments' 'TIMELINE' 'v_report_invoice_adjustments_daily'

install_ddl $REPORTS/v_report_invoice_item_adjustments_daily.ddl
create_report 'invoice_item_adjustments_daily' 'Invoice item adjustments' 'TIMELINE' 'v_report_invoice_item_adjustments_daily'

install_ddl $REPORTS/v_report_invoice_item_credits_daily.ddl
create_report 'invoice_item_credits_daily' 'Invoice credits' 'TIMELINE' 'v_report_invoice_item_credits_daily'

install_ddl $REPORTS/invoices_balance_daily/v_report_invoices_balance_daily.ddl
create_report 'invoices_balance_daily' 'Invoice balance' 'TIMELINE' 'v_report_invoices_balance_daily'

install_ddl $REPORTS/invoices_daily/v_report_invoices_daily.ddl
create_report 'invoices_daily' 'Invoices' 'TIMELINE' 'v_report_invoices_daily'

install_ddl $REPORTS/mrr/v_report_mrr_daily.ddl
create_report 'mrr_daily' 'MRR' 'TIMELINE' 'v_report_mrr_daily'

install_ddl $REPORTS/new_accounts_daily/v_report_new_accounts_daily.ddl
create_report 'new_accounts_daily' 'New accounts' 'TIMELINE' 'v_report_new_accounts_daily'

install_ddl $REPORTS/v_report_overdue_states_count_daily.ddl
create_report 'overdue_states_count_daily' 'Overdue states' 'TIMELINE' 'v_report_overdue_states_count_daily'

install_ddl $REPORTS/payments_total_daily/v_report_payments_total_daily_sub1.ddl
install_ddl $REPORTS/payments_total_daily/v_report_payments_total_daily.ddl
create_report 'payments_total_daily' 'Payment ($ amount)' 'TIMELINE' 'v_report_payments_total_daily'

install_ddl $REPORTS/refunds_total_daily/v_report_refunds_total_daily.ddl
create_report 'refunds_total_daily' 'Refunds' 'TIMELINE' 'v_report_refunds_total_daily'

install_ddl $REPORTS/v_report_trial_starts_count_daily.ddl
create_report 'trial_starts_count_daily' 'Trials' 'TIMELINE' 'v_report_trial_starts_count_daily'

# System views
for r in `find $SYSTEM -type f -name '*.sql' -o -name '*.ddl' -maxdepth 1`; do install_ddl $r; done

create_report 'system_report_control_tag_no_test' 'Control tags' 'COUNTERS' 'v_system_report_control_tag_no_test'
create_report 'system_report_notifications_per_queue_name' 'Notification queues' 'TIMELINE' 'v_system_report_notifications_per_queue_name'
create_report 'system_report_notifications_per_queue_name_late' 'Late notifications' 'COUNTERS' 'v_system_report_notifications_per_queue_name_late'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
create or replace view v_system_report_payments_per_day as
select
tenant_record_id
, date_format(greatest(created_date, updated_date), '%Y-%m-%d') as day
, date_format((case when created_date > updated_date then created_date else updated_date end), '%Y-%m-%d') as day
, case
when state_name IN ('AUTH_ERRORED', 'CAPTURE_ERRORED', 'CHARGEBACK_ERRORED', 'CREDIT_ERRORED', 'PURCHASE_ERRORED', 'REFUND_ERRORED', 'VOID_ERRORED') then 'ERRORED'
when state_name IN ('AUTH_FAILED', 'CAPTURE_FAILED', 'CHARGEBACK_FAILED', 'CREDIT_FAILED', 'PURCHASE_FAILED', 'REFUND_FAILED', 'VOID_FAILED') then 'FAILED'
Expand Down