Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow deleting and updating sites and users from the CLI #344

Closed
anarcat opened this issue Jul 15, 2020 · 9 comments · Fixed by #457
Closed

Allow deleting and updating sites and users from the CLI #344

anarcat opened this issue Jul 15, 2020 · 9 comments · Fixed by #457

Comments

@anarcat
Copy link

anarcat commented Jul 15, 2020

since #120, there's now a create command which is great, but there is no remove command that I can find. I created a test site in my instance - how do I delete it? :)

thanks for this great software!

@arp242
Copy link
Owner

arp242 commented Jul 15, 2020

Ehm, there's no way to do that right now 😅

It probably makes the most sense to expose the "delete site" in settings (currently only enabled for goatcounter.com) with some minor changes rather than adding a new CLI subcommand.

@anarcat
Copy link
Author

anarcat commented Jul 18, 2020

ah, i see the tab, but now i'm a little confused: i thought that, when i created a "site", i created a goatcounter site, not a site being tracked. what happens when i hit that "delete site" tab? It seems to say it deletes the site being tracked but for some reason I was under the impression that goatcounter create -d foo was creating the analytics site. I think that's because of this blurb in the create usage:

  -domain      Domain to host e.g. "stats.example.com". The site will be
               available on this domain only, so "stats.example.com" won't be
               available on "localhost".

... ie. stats.example.com there made me think I was creating stats.example.com which could track example.com, foo.example.com and whateverelse.com, not example.com itself...

In general, I get confused between the Site settings and Domain settings field. I feel the one provided in -domain is the latter, but is it? And why is there a distinction?

Can multiple "sites" be tracked by a single "goatcounter site"?

Maybe that could desserve a new ticket though... :)

@anarcat
Copy link
Author

anarcat commented Jul 18, 2020

In other words: I have created both analytics.anarc.at and anarc.at here. I have access to the former, which is the live tracker, but I somehow don't remember how I created the former, nor how to delete it. I suspect I would need to create a anarc.at "site" somehow, or access it in a web browser under that name, but I can't quite wrap my head around that right now...

It would be real nice to have "CRUD" (create/read/update/delete) on the sites (especially "list and delete" i guess) on the commandline to find those orphan sites...

Thanks again, in any case!

@arp242
Copy link
Owner

arp242 commented Jul 18, 2020

The -domain you use with goatcounter create is the domain you want to serve GoatCounter on: analytics.anarc.at in your case.

You can send whatever you want from whereever you want; it's all the same to GoatCounter. It doesn't need to know that your site is anarc.at, and you don't need to fill that in anywhere.

You can optionally fill in anarc.at in the top-left domain in the settings ("Your site’s domain"), that's not really used for anything except linking to the paths in the dashboard. Maybe I should rename that to "Your site" because two "Domain"s in the backend is perhaps a bit confusing.


As for the CLI, I thought about that, but I don't really want to make the CLI too complex. On the other hand, if you create a site you can't access (which is what you did) or make a typo, then you can never update or delete it without manual DB frobbing 🤔 Need to think a bit on how to best do this, and also thinking about the future when GoatCounter supports multiple users (which also needs some CLI-fu).

The "obvious way" is goatcounter site update [..] and goatcounter user delete [..] etc., but I'm not sure if I like that. Something like this would probably be better:

Management commands:
  select       Select/list table rows.
  insert       Insert a new table row.
  update       Update an existing table row.
  delete       Delete a table row.
goatcounter select -table users
goatcounter select -table sites -where "code like 'foo%'"

goatcounter create -table sites cname=foo.com

goatcounter update -table sites -where id=1 domain=foo

goatcounter delete -table sites -where id=1

And we can keep create as a convenient shortcut.

It's a little bit more work, but would also be a lot more future-proof and flexibe 😅

@arp242
Copy link
Owner

arp242 commented Jul 18, 2020

In the meanwhile, if you want to delete the site you can use:

update sites set state='d', updated_at='2020-01-01 00:00:00' where cname='anarc.at';

In the SQLite or PostgreSQL CLI and it'll be deleted by the cron job (runs every 12 hours and on server startup/shutdown).

@anarcat
Copy link
Author

anarcat commented Jul 18, 2020

In the meanwhile, if you want to delete the site you can use:

update sites set state='d', updated_at='2020-01-01 00:00:00' where cname='anarc.at';

Hmm... maybe that's good enough and a docs update would suffice. ;) After all, reimplementing SQL on the commandline might not be necessary...

In the SQLite or PostgreSQL CLI and it'll be deleted by the cron job (runs every 12 hours and on server startup/shutdown).

... cron job? I have a cron job?

@arp242
Copy link
Owner

arp242 commented Jul 23, 2020

docs update would suffice.

Yeah, dunno; wouldn't be in favour of telling people to run manual SQL queries; it's hard for non-technical people, and easy to typo and screw things up.

reimplementing SQL on the commandline might not be necessary...

Yeah, a full SQL-interface might be a bit too much, although it wouldn't be hard to do. Was thinking out loud with the previous CLI interface, but I do like the idea of a generic(-y) CRUD interface, rather than a complex CLI with loads of commands and subcommands. Ideally, the goatcounter help overview should fit in a 80x24 terminal window

... cron job? I have a cron job?

It's just a cron package in GoatCounter itself which runs stuff periodically (while(1) { run_stuff && sleep }); not the system cron 😅

@arp242 arp242 changed the title how do we *remove* a site? Allow deleting and updating sites and users from the CLI Jul 23, 2020
@arp242 arp242 added this to the Planned milestone Jul 23, 2020
@arp242 arp242 reopened this Jul 23, 2020
@anarcat
Copy link
Author

anarcat commented Jul 28, 2020

It's just a cron package in GoatCounter itself which runs stuff periodically (while(1) { run_stuff && sleep }); not the system cron sweat_smile

so that runs magically in the background somewhere (as a coroutine?) or do i need to configure something myself?

@arp242
Copy link
Owner

arp242 commented Jul 28, 2020

Nah, it's magic 🧙‍♂️

arp242 added a commit that referenced this issue Mar 16, 2021
…"; expand "goatcounter db" to create API keys;

You can now have multiple users for a site, each with their own login.
Having permissions and settings per-user isn't implemented yet.

Having a single "db" command for all database management is a bit
clearer, and also allows expanding to other things such as "goatcounter
db create user".

This removes the -site=1 option from "goatcounter import", as that was
more confusing than anything else. You can now use "goatcounter db
create apikey" if you want to make an API key from a script.

Ref #2
Fixes #344
arp242 added a commit that referenced this issue Mar 20, 2021
…"; expand "goatcounter db" to create API keys;

You can now have multiple users for a site, each with their own login.
Having permissions and settings per-user isn't implemented yet.

Having a single "db" command for all database management is a bit
clearer, and also allows expanding to other things such as "goatcounter
db create user".

This removes the -site=1 option from "goatcounter import", as that was
more confusing than anything else. You can now use "goatcounter db
create apikey" if you want to make an API key from a script.

Ref #2
Fixes #344
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants