about summary refs log tree commit diff
path: root/db/views
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-12-15 18:19:20 +0100
committerGitHub <noreply@github.com>2020-12-15 18:19:20 +0100
commit92cfcf168cae094ece281b3cb6d0f5b1539a8c25 (patch)
tree070a16d495d962a1f4efb9e196fae18803cf3835 /db/views
parent1978f7265e1e83bda25413da26f53c53110af764 (diff)
parentb0722fbc14cf1cee412c3524c51705c9902bde7f (diff)
Merge pull request #1476 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'db/views')
-rw-r--r--db/views/instances_v01.sql17
1 files changed, 17 insertions, 0 deletions
diff --git a/db/views/instances_v01.sql b/db/views/instances_v01.sql
new file mode 100644
index 000000000..94acd61a1
--- /dev/null
+++ b/db/views/instances_v01.sql
@@ -0,0 +1,17 @@
+WITH domain_counts(domain, accounts_count)
+AS (
+  SELECT domain, COUNT(*) as accounts_count
+  FROM accounts
+  WHERE domain IS NOT NULL
+  GROUP BY domain
+)
+SELECT domain, accounts_count
+FROM domain_counts
+UNION
+SELECT domain_blocks.domain, COALESCE(domain_counts.accounts_count, 0)
+FROM domain_blocks
+LEFT OUTER JOIN domain_counts ON domain_counts.domain = domain_blocks.domain
+UNION
+SELECT domain_allows.domain, COALESCE(domain_counts.accounts_count, 0)
+FROM domain_allows
+LEFT OUTER JOIN domain_counts ON domain_counts.domain = domain_allows.domain