goatcounter
                                
                                
                                
                                    goatcounter copied to clipboard
                            
                            
                            
                        Unable to delete site
Thanks for the amazing project!
Unfortunately, I'm not able to delete a site after creating other sites:
Server info:
Version:   v2.4.1
Go:        go1.19.3 linux/arm64 (race=false cgo=true)
Database:  SQLite 3.39.4
Uptime:    21h59m30s
Error:
Oct 15 09:03:15 ERROR: Site.Delete: site 1 has 6 linked sites {code="12lfbn0" http_host="stats-spellebel.jensw.be" http_method="POST" http_url="/settings/sites/remove/1" ... }
Configured sites (tried to delete the one with the arrow):
Sites in DB:
[
  {
    "site_id": 1,
    "parent": null,
    "code": "serve-1ue98tzr8puf2",
    "link_domain": "jensw.be",
    "cname": "stats.jensw.be",
    "cname_setup_at": "2021-06-03 19:26:07",
    "settings": "{\"public\":\"public\",\"allow_counter\":false,\"allow_bosmang\":false,\"data_retention\":0,\"campaigns\":\"utm_campaign,utm_source,ref\",\"ignore_ips\":\"\",\"collect\":255,\"collect_regions\":\"US,RU,CH\"}",
    "user_defaults": "{\"twenty_four_hours\":true,\"sunday_starts_week\":false,\"language\":\"\",\"date_format\":\"02-01-2006\",\"number_format\":8239,\"timezone\":\"BE.Europe/Brussels\",\"widgets\":[{\"n\":\"pages\",\"s\":{\"limit_pages\":10,\"limit_refs\":10}},{\"n\":\"totalpages\",\"s\":{\"align\":false,\"no-events\":false}},{\"n\":\"toprefs\"},{\"n\":\"browsers\"},{\"n\":\"systems\"},{\"n\":\"sizes\"},{\"n\":\"locations\"},{\"n\":\"languages\"}],\"views\":[{\"name\":\"default\",\"filter\":\"\",\"daily\":false,\"period\":\"week\"}],\"email_reports\":0}",
    "received_data": 1,
    "state": "a",
    "created_at": "2021-06-03 19:26:07",
    "updated_at": "2021-06-04 21:07:04",
    "first_hit_at": "2021-06-03 19:26:07"
  },
  {
    "site_id": 2,
    "parent": 1,
    "code": "serve-1gq6ca1xg65hl",
    "link_domain": "bjoetiek-y.be",
    "cname": "stats.bjoetiek-y.be",
    "cname_setup_at": "2021-06-03 19:46:28",
    "settings": "{\"public\":\"public\",\"allow_counter\":false,\"allow_bosmang\":false,\"data_retention\":0,\"campaigns\":\"utm_campaign,utm_source,ref\",\"ignore_ips\":\"94.105.122.168\",\"collect\":255,\"collect_regions\":\"US,RU,CH\"}",
    "user_defaults": "{\"twenty_four_hours\":true,\"sunday_starts_week\":false,\"language\":\"\",\"date_format\":\"02-01-2006\",\"number_format\":8239,\"timezone\":\"BE.Europe/Brussels\",\"widgets\":[{\"n\":\"pages\",\"s\":{\"limit_pages\":10,\"limit_refs\":10}},{\"n\":\"totalpages\",\"s\":{\"align\":false,\"no-events\":false}},{\"n\":\"toprefs\"},{\"n\":\"browsers\"},{\"n\":\"systems\"},{\"n\":\"sizes\"},{\"n\":\"locations\"},{\"n\":\"languages\"}],\"views\":[{\"name\":\"default\",\"filter\":\"\",\"daily\":false,\"period\":\"week\"}],\"email_reports\":0}",
    "received_data": 1,
    "state": "a",
    "created_at": "2021-06-03 19:46:28",
    "updated_at": "2021-06-03 20:26:57",
    "first_hit_at": "2021-06-03 19:46:28"
  },
  ...
]
I see there is no default in the db for parent, therefore I assume it's set in the code:
CREATE TABLE sites (
	site_id        integer        primary key autoincrement,
	parent         integer        null,
	code           varchar        not null                 check(length(code) >= 2 and length(code) <= 50),
	link_domain    varchar        not null default ''      check(link_domain = '' or (length(link_domain) >= 4 and length(link_domain) <= 255)),
	cname          varchar        null                     check(cname is null or (length(cname) >= 4 and length(cname) <= 255)),
	cname_setup_at timestamp      default null             check(cname_setup_at = strftime('%Y-%m-%d %H:%M:%S', cname_setup_at)),
	settings       varchar        not null,
	user_defaults  varchar        not null default '{}',
	received_data  integer        not null default 0,
	state          varchar        not null default 'a'     check(state in ('a', 'd')),
	created_at     timestamp      not null                 check(created_at = strftime('%Y-%m-%d %H:%M:%S', created_at)),
	updated_at     timestamp                               check(updated_at = strftime('%Y-%m-%d %H:%M:%S', updated_at)),
	first_hit_at   timestamp      not null                 check(first_hit_at = strftime('%Y-%m-%d %H:%M:%S', first_hit_at))
);
Based on https://github.com/arp242/goatcounter/issues/165#issuecomment-751230188, I assumed there wouldn't be any parent <=> child relationship anymore.
So, could you please
- have a look why 
stats.jensw.becannot be deleted? - explain what's the remaining usage of the parent <=> child relationship?