2019-12-02

<rpifan> ive got a bunch of random bad users but at least i know now
<rpifan> ok that user is gone
<rpifan> ok sigh a whole bunch of stuff references that one user
<rpifan> turns out only that users it own id self rered
<rpifan> cool
<rpifan> im more familiar with sql
<rpifan> ah
<rpifan> yourmodel?
<rpifan> how can i updated the created by colum to that number for all the other users
<rpifan> ok so the real admin user is 141
<NL3limin4t0r> rpifan: But yeah, all records that point to that user have to be updated if you're planning to delete the user.
<NL3limin4t0r> rpifan: You could for example add a "disabled_at" column that is set when a user is disabled.
<NL3limin4t0r> rpifan: A better option might be to disable users instead of simply deleting the entrire record. This allows other records to still point to them.
<rpifan> or is that command going to update all the user created by entries
<rpifan> wont that destroy all the otehr links
<rpifan> hmm im thinking now if i delet ethis user 366 it seems to be the created of all users
<NL3limin4t0r> rpifan: UPDATE `table_name` SET `column_name` = 1234 WHERE `table_name`.`id` = 1234
<rpifan> so how do i do that in mysql set created_by_id = 256
<rpifan> ?
<rpifan> yea i got it
<havenwood> rpifan: It's a multi-codepoint Emoji.
<rpifan> ahh
<havenwood> rpifan: that sounds reasonable. 👍🏽
<rpifan> and then delete it
<rpifan> so can i change the created by id to 256
<rpifan> but it was updated by id 266
<rpifan> it is id 366 but it says it was also created by id 366
<rpifan> i think i understand
<NL3limin4t0r> rpifan: aka your current schema does allow NULL values in that column.
<rpifan> created_by_id | int(11) | NO | MUL | NULL
<NL3limin4t0r> rpifan: That depends what the referencing record is. If it's an important record you might not want to delete it. You could also migrate the records that point to the user you want to delete, and let them point to the system user instead.
<rpifan> NL3limin4t0r, i found a refende to id 366 should i just delete the entry from the db?
<rpifan> yea that was the result
<rpifan> def | zammad | fk_rails_45307c95a3 | zammad | users | FOREIGN KEY
<NL3limin4t0r> rpifan: ^
<rpifan> so i read the previous stuff and found a table called users
<NL3limin4t0r> rpifan: Last time you posted this link: https://pastebin.com/8pcTq0AD which says that the foreign key "fk_rails_45307c95a3" is blocking the deletion because some "created_by_id" column is still refereing to the user id.
<rpifan> yea i was checking
<havenwood> rpifan: Those ^ are pasted from the 29th. Maybe re-read the part of the log that mentions your name: https://freenode.irclog.whitequark.org/ruby/search?q=rpifan
<havenwood> rpifan: Check: User.where(created_by_id: 366)
<havenwood> rpifan: There's a #created_by_id reference to another User id—that's the foreign key.
<rpifan> well where do i find this foreign key
<NL3limin4t0r> rpifan: Running `as_array(data)` results in the same output for both inputs.
<rpifan> NL3limin4t0r, i got into the db how do i find the missing table
<rpifan> now i know its all in mysql
<rpifan> if i nullify the association wont i break it?
<rpifan> so its basically saying there is something in the database that is still refering ot the user?
<NL3limin4t0r> rpifan: It's not to hard, you just have some foreign key constraint blocking the deletion of a record. If you find out which record refers to the user and remove that record, or nullify the association you should be good.
<rpifan> so im just gonna solve it myself
<rpifan> so the zammad ppl didnt help
<NL3limin4t0r> rpifan: hey
<rpifan> NL3limin4t0r, hello
<rpifan> hello

2019-11-29

<rpifan> thanks
<rpifan> oh well
<rpifan> well nice weekend y'all. i gotta come in to work tommorow to do redo the network rack
<rpifan> yea thats true, i had hoped this owuld be a set it and forget it kind of deal but i see its not. At least it gives me something to work on when im bored at wokr
<rpifan> i really appreacite y'all help in gettin gme ot understand a littel bit more how this set up works. I'm not even sure how to log into the db as it was all setup by the zamad script
<rpifan> its ok i just wrote on the zammad support forum
<NL3limin4t0r> rpifan: You can find out which table has issues with the deletion of a user with the following query: SELECT * FROM information_schema.table_constraints WHERE `CONSTRAINT_SCHEMA` = 'database name' AND `CONSTRAINT_NAME` = 'fk name'
<rpifan> and it still has that issue
<rpifan> i just purged all the tickets just in case
<rpifan> so i would delete the records in mysql or the records in the main system
<NL3limin4t0r> rpifan: Although deleteing the foreign key is certainly an option, I personally wouldn't recommend it. Check in you database whate reference the fk_rails_45307c95a3 foreign key validates, there might still be some records pointing to the user.
<rpifan> references: {"tickets_closed"=>1, "tickets_open"=>0}, updated_by_id: 256, created_by_id: 366
<havenwood> rpifan: Check: User.where(created_by_id: 366)
<havenwood> rpifan: They say in that ticket to remove or reassign any references. So here, you'd need to reassign. the created_by_id before deleting this person.
<havenwood> rpifan: Tell them a foreign key constraint on created_by_id is preventing.
<rpifan> they do say u r supposd to
<havenwood> rpifan: Maybe they disable a User instead of deleting them? Ask the programmer if this is something you think you should be able to do.
<rpifan> im just using the rails console
<rpifan> well im not programming the thing
<rpifan> hm
<havenwood> rpifan: The Rails docs show how remove foreign keys: https://guides.rubyonrails.org/active_record_migrations.html#foreign-keys
<rpifan> and i guess writing to mysql
<rpifan> this is doing AD auth
<rpifan> well
<havenwood> rpifan: The constraint is the DB insisting those foreign keys be valid. This is optional though, since you might want to "nullify" the reference or delete the foreign record entirely. Up to you! https://dev.to/kevincolemaninc/how-and-when-to-add-foreign-key-constraints-1aji
<rpifan> i see
<havenwood> rpifan: There's a #created_by_id reference to another User id—that's the foreign key.
<rpifan> its zammad
<rpifan> since im just using this app
<rpifan> idk what exactly that means
<rpifan> i just want to delet that user
<havenwood> rpifan: You can remove foreign key constraints you don't want.
<havenwood> rpifan: Do you want that constraint ensuring there's a valid foreign key?
<rpifan> oh
<ruby[bot]> rpifan: we in #ruby do not like pastebin.com, it loads slowly for most, has ads which are distracting and has terrible formatting. Please use https://gist.github.com
<rpifan> im trying to delete a user
<havenwood> rpifan: ask away
<rpifan> can i get some ruby support for a different project built on rails
<rpifan> hows it going
<rpifan> hello