#!/usr/bin/env schema

MODELS =					\
	beancount.sql

# Note: I keep the HTML files checked in on purpose, it is part of how I
# maintain the website.

.SUFFIXES: .txt .sql .db .create .test .clean .html

all: sql

# Note: this uses a private script called 'projects' that I have to update pages
# in a way that looks good on my website. It invokes a custom-made script not
# unlike rst2html.py, which inserts a div for the header and a few relative
# links that work well by default. See beancount/etc/docutilsrc for the list.
docs:
	projects docs beancount

.txt.html:
	rst2html.py $< > $(<:.txt=.html)

sql: $(MODELS)

.txt.sql:
	-rm -f $@
	echo "-- This file is auto-generated by rst-literals. Do not modify." > $@
	rst-literals -t sql $< >> $@
	chmod a-w $@

.sql.clean:
	dropdb $(<:.sql=.db)

.sql.create:
	-dropdb $(<:.sql=.db) >/dev/null
	createdb $(<:.sql=.db)
	psql -f $< $(<:.sql=.db) 2>&1 | grep -v NOTICE:

.sql.test:
	psql -f $(<:.sql=test.sql) $(<:.sql=.db) 2>&1 | grep -v NOTICE:

examples:
	rst-literals -s accounting.txt >/dev/null

clean:
	rm -f $(MODELS)
