# This is the migration makefile.
#
# WHAT IS NEEDED FOR THE MIGRATION:
#
# - $(SQLDB): a dump of the SQL database (format: login password domain)
#
# HOW MIGRATION WORKS, STEP BY STEP (`migration` rule):
#
# 1. migration-file    -> create the $(USER_DB) file
# 2. migrate-all-users -> migrate all user accounts
#
# AFTER THE `migration` RULE: go to the dnsmanagerd repository and follow instructions.

# DB from SQL, format: login password domain
SQLDB ?= /tmp/usrdb

USER_DB ?= /tmp/migration-authd-user-db.txt

$(USER_DB):
	./bin/migration-filter.awk < $(SQLDB) | grep -a -v "^INVALID" | sort | uniq > $(USER_DB)

migration-file: $(USER_DB)

migrate-user:
	./bin/authc user migrate $(NAME) $(PASSWORD_HASH) $(LOGIN_OPT)

migrate-all-users:
	@echo "Don't forget the admin login, for example: LOGIN=dnsmanager"
	./bin/authc migration-script $(USER_DB) $(LOGIN_OPT)

migration: migration-file migrate-all-users