The idiom like rats fleeing a sinking ship, used in reference to people abandoning an enterprise once it seems likely to fail, has shown great linguistic tenacity, having been in regular use for over four hundred years. However, the wording and form of this standby has changed quite a bit over the centuries.
The original setting for the fleeing rats was a decrepit house, one that was on the verge of falling down. Both rats and mice, in the 16th century, were said to have the ability to know when a structure was on the verge of collapse, and would accordingly decamp some time before this happened. By the early 17th century the behavior of the rats begins to see use as a simile.
Don't suffer your Selves to be buffetted from Post to Pillar, by Pinning your Faith upon such that propose no more than to find a way out for themselves, like Rats that quit the House before it falls.
— Anon., A Dialogue Between Two Members of the New and Old East-India Companies, 1600Some think, that the Rationall Spirits flye out of Animals, (or that Animall we call Man) like a swarm of Bees, when they like not their Hives, finding some inconvenience, seek about for another Habitation: Or leave the Body, like Rats, when they finde the house rotten, and ready to fall.
— Margaret Cavendish Newcastle, Philosophical Fancies, 1653
Like rats fleeing a rotten house may have had a certain ring to it, but other competing forms came about as the 17th century progressed. The first of these to appear was the image of the rodent fleeing a burning house.
She lookes to her riches, and finds that those bribes will not be taken: to her friends, and perceives them to be in as much danger as herselfe: to her old companions, carnall delights, the common refuge of melancholy sinners; and sees them running from her affrighted, like rattes from a house on fire.
— Thomas Adams, A Commentary, 1633Yea, if but sicknesse come, these carnall delights will runne from you, affrighted like Rats from a house on fire.
— Richard Younge, The Drunkard’s Character, 1638
It is not until the latter portion of the 17th century that the rats decide they’ve had enough of running from collapsing and burning houses, and the expression took on a new mode of egress: decamping from a foundering ship.
…have they made any renunciation since, of any of those doctrines which were thought so dangerous then? or are they quite gone from us, and to use Mr. Cressy's own comparison, like Rats have forsaken a sinking Ship?
— Edward Stillingfleet, An Answer to Mr. Cressy’s Epistle, 1675What Subsidies have you had from….your Popish Party? Alas, like Rats, they forsake a falling-House, or a sinking Ship.
— Titus Oates, Eikon Vasilike Trite, 1697
Rats continued to flee (or quit, abandon, and desert) houses that were falling down or burning, as well as doing the same with an increasing number of sinking ships throughout the 18th century. At the start of the 19th century there was another change in the idiom, as it dropped the like and began to be used as metaphor.
Rats deserting the sinking ship!—We last week mentioned the dissatisfaction to the cause of federalism of the Hon. Mr. Chamberlain, at present member of the National Congress.
— New Hampshire Patriot (Concord, NH), 10 Jul. 1810Rats deserting the sinking ship. As soon as Mr. Jefferson perceived that the power of Bonaparte was on the wane, he joined in the cry for the cause of the virtuous “Alexander the Deliverer.”
— Federal Republican (Georgetown, District of Columbia), 3 Jan. 1814It is not known whether she was sent westward to advocate the separation of Maine, or was going to Washington to catch some of the rats about deserting the ship of state.
— Buffalo Gazette (Buffalo, NY), 15 Oct. 1816Rats deserting the sinking Ships. It is a maxim among sailors that before the vessel is to be lost the Rats will desert her. There has been a wonderful desertion of Rats lately from the Federal Ship.
— Vermont Republican (Windsor, VT), 18 Mar. 1816
This metaphor seems to have started with rats deserting the sinking ship, and toward the middle of the 19th century added the variants of abandoning or fleeing the vessel. While there is considerable variation of verb employed to describe what the rats are doing, there is less in terms of the situations that these idioms were applied to; almost all of these early uses are in reference to political scandals.
Gibson L. Cranmer….is announced in the last Springfield Journal as a candidate for Presidential Elector to support the claims of Martin Van Buren. This the rats are abandoning the sinking ship in all quarters.
— Lancaster Gazette (Lancaster, OH), 29 Sept. 1848Two of McKane’s indicted election heelers were surrendered by their bondsmen, and locked up in Raymond Street Jail….The rats are fleeing; the ship of fraud is sinking.
— The Evening Journal (Wilmington, DE), 21 Mar. 1894
Given that the continued existence of rats and failing enterprises (political and otherwise) appears to be as likely as that of death and taxes, there is is a strong likelihood that this expression will continue to inhabit our language in decades and centuries to come. However, when we see how much it has shifted over the past four hundred or so years it is less certain what the future forms will be. Perhaps like rats disinvesting in a bear market?