Migration: can generate migration files.

migration
Philippe PITTOLI 2024-06-09 04:14:10 +02:00
parent cb8b0c93a1
commit 2509e8af15
4 changed files with 71 additions and 1 deletions

View File

@ -104,6 +104,27 @@ print-response-message-numbers:
print-response-messages-without-comments:
make -s print-response-messages | grep -vE '^[[:blank:]]+#'
MIGRATION_FILE_INIT ?= /tmp/dnsmanager-migration-init.txt
MIGRATION_FILE_INTERMEDIARY ?= /tmp/dnsmanager-migration-intermediary.txt
MIGRATION_FILE_TARGET ?= /tmp/dnsmanager-migration-target.txt
migrate:
# Format entries: one per line.
./bin/format.awk < $(MIGRATION_FILE_INIT) |\
./bin/fix-last-element.awk |\
# Remove 'activated' attribute. No longer relevant (never, actually). \
sed 's/ \+activated \+=> \+0, \+//' |\
sed 's/domain \+=> \+/"domain": /' |\
sed 's/ \+login \+=> \+/"login": /' |\
sed 's/", \+}/" }/' |\
# Fix @ in logins. \
sed 's/\\@/@/' |\
# Remove obvious SQL hacks. \
sed '/))))/d' |\
sed '/: \+[0-9]\+,/d' |\
# Remove all entries with accents. \
grep -v '\\' > $(MIGRATION_FILE_INTERMEDIARY)
./bin/migration-final.awk < $(MIGRATION_FILE_INTERMEDIARY) | sort -n > $(MIGRATION_FILE_TARGET)
wipe-db:
rm -r $(DBDIR)

22
bin/fix-last-element.awk Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/awk -f
BEGIN {
data = ""
}
/^\]/ {
gsub("},$","}",data)
print data
print
next
}
/},$/ {
print data
data = $0
next
}
{
data = $0
}

View File

@ -5,7 +5,7 @@ BEGIN {
}
/^\[/ || /^\]/ {
print "oups"
print
next
}

27
bin/migration-final.awk Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/gawk -f
/^\[/ || /^\]/ {
next
}
{
domain = $0
login = $0
gsub("^.+domain\": \"", "", domain)
gsub("\",\"login\": .+", "", domain)
gsub(".+\",\"login\": \"", "", login)
gsub("\" }.?$", "", login)
data[login][domain] = 1
}
END {
for ( login in data ) {
domains = ""
nb = 0
for ( domain in data[login] ) {
nb += 1
domains = (domains "\t" domain)
}
print nb, login, domains
}
}