News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Append topic/messages from one database to another

Started by JTVaughn, April 19, 2014, 05:39:15 AM

Previous topic - Next topic

JTVaughn

I thought I'd try moving a topic over from one database to another (for reasons too long to go into, but worth noting most of the users on both forums are identical).

I tried using this guide: http://www.simplemachines.org/community/index.php?topic=302767.msg2002810#msg2002810

I get as far as step 6, but then got a "Duplicate entry '130866' for key 'PRIMARY'" error, which is obviously because there's already a post with the ID of 130866 in the database (in id_msg).

Is it possible to append the topic and containing posts? So instead of copying the topic ID and post IDs exactly, I tell the SQL query to give them new IDs that follow on from the last known posts? Or would that cause other problems?

Thanks for any advice you can give.

margarett

Yes, just omit the "ID_MSG" (twice in that query). It is an auto-increment field, so it will insert it.

You will need to recount all forum totals after you do this operation
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

JTVaughn


Irisado

Is your forum 1.1.x or 2.0.x?  You refer to a thread in 1.1.x support, so I assume the former?  Please clarify, and I'll move this to a board where you are likely to receive more responses.
Soñando con una playa donde brilla el sol, un arco iris ilumina el cielo, y el mar espejea iridescentemente

JTVaughn

It's 2.0.x. The code is still relevant, just required a bit of tweaking to the field names

Irisado

Thanks :).  I'll move it to the appropriate support board, as this board isn't for SMF forum coding.
Soñando con una playa donde brilla el sol, un arco iris ilumina el cielo, y el mar espejea iridescentemente

JTVaughn

It worked! Thanks to much margarett.

Marking this solved.

JTVaughn

Actually, I have a follow-up question.

The topic I moved has now flooded the recent posts box, which is understandable as it's been appended rather than integrated. One kink however is that it's not showing the right "last post by" information in the board view. For instance, it says the last reply was done in Jan, but it was actually done this week. Is there any way to correct this, or is it just a quirk of the process? I've recounted the totals already.

margarett

That's a quirk of the process... The latest topics aren't acquired by date, rather by ID (which is usually the same thing). Since you added new IDs to the table, even if they are older than the new ones (now I got myself lost :P )...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

JTVaughn

I guess I can live with that, as long as everything updates correctly and works when there's a new reply to the moved topics

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

JTVaughn

Next question :D

Can I move multiple topics at once? Is it possible? Or am I biting off more than I should be.

margarett

Probably

QuoteYou can also probably replace the WHERE clause in the two queries with WHERE ID_TOPIC IN (topic1, topic2, topic3).

So if you use that you can specify several topics at once, comma separated.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

JTVaughn

Ack, I'm so stupid, I tried that but I totally missed the "IN" in there. Thanks.

Tried that, it moved the topic fine, but I'm getting "This topic doesn't exist on this board" when trying to access it, and it doesn't exist when I go in the board. I'm assuming the 2nd part didn't work (the INSERT INTO smf_topics bit). The query seemed to work (2 rows inserted) though.

margarett

No idea. Did you perform the maintenance tasks?
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

JTVaughn

Quote from: margarett on April 19, 2014, 01:56:28 PM
No idea. Did you perform the maintenance tasks?

Yup. It's weird. Everything seems to be in the database fine.

Hmm. I deleted the topics and messages from the database and started again, this time doing only 1 of the topics instead of 2 at once, and I'm getting the "This topic doesn't exist on this board" error again.

I'm stumped. It worked so well with the first topic.

margarett

I'm not sure, sorry. I can think on *so* many things that can be broken with that method, so I will not really encourage you to do it any further. If you really want to, try this is a test forum, not in a live one ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

JTVaughn

Quote from: margarett on April 19, 2014, 02:56:25 PM
I'm not sure, sorry. I can think on *so* many things that can be broken with that method

haha, you should've said that at the start ;)

Annoying I can't find a way :(

Kindred

If it's just one message, the. Why not just copy/paste in the forum itself?

Basically, you are trying to do something which the forum is not intended to do, and which involves more than just one row or one table...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: