我是个白痴......搞砸了Rails的迁移:
思考迁移将像模型生成器一样工作(使用references:modelname
)我做了以下事情:
$ rails g migration add_event_to_photos references:event
Run Code Online (Sandbox Code Playgroud)
这创造了迁移
class AddEventToPhotos < ActiveRecord::Migration
def change
add_column :photos, :references, :event
end
end
Run Code Online (Sandbox Code Playgroud)
现在我的开发数据库(SQLite3)在表中有一个references
类型event
的photos
列.
我的schema.rb中间有一行说:
# Could not dump table "photos" because of following StandardError
# Unknown type 'event' for column 'references'
Run Code Online (Sandbox Code Playgroud)
rake db:rollback
无能为力:
$ rake db:rollback
== AddEventToPhotos: reverting ===============================================
-- remove_column("photos", :references)
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `to_sym' for nil:NilClass …
Run Code Online (Sandbox Code Playgroud) 虽然我经常使用Git,但我还是初学者.
有时,我犯了一个错误,但只有在我提交之后才发现它.在那时,我通常不得不花费很长时间在互联网上寻找我应该用来摆脱它的命令(在推送之前).
每当发生这种情况时,我发现自己想知道我经常遇到的四个术语之间的区别是什么:
我认为现在是时候一劳永逸地学习这些差异了.这些是什么?
给出从会话bean调用两个Web服务方法的示例,如果在对两个方法的调用之间抛出异常,该怎么办?在不调用Web服务的情况下,事务将回滚并且不会造成任何损害.但是,Web服务不会回滚.当然,即使使用单一的Web服务也存在问题.虽然这是一个通用问题,但我对与EJB会话bean有关的解决方案感兴趣.
一个简单而定制的答案是为Web服务为每个"真实功能"方法添加一个特殊的"回滚方法".我要求的是一些标准化的方法.
我在尝试使用Spring-test时没有成功地获得JDBC事务回滚.当我运行以下内容时,始终会提交SQL更新.
package my.dao.impl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.transaction.TransactionConfiguration;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Statement;
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class})
@ContextConfiguration(locations={"classpath:ApplicationContext-test-DAOs.xml"})
@TransactionConfiguration(defaultRollback = true)
public class ConfirmationMatchingDAOImplTest {
@Autowired
private DataSource dataSource;
@Test
public void shouldInsertSomething() throws Exception {
final Connection connection = dataSource.getConnection();
final Statement statement = connection.createStatement();
statement.executeUpdate("insert into TEST_INSERT values (1, 'hello')");
statement.close();
connection.close();
}
}
Run Code Online (Sandbox Code Playgroud)
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="url" value="jdbc:sqlserver://makeitfunky:1490;databaseName=fonzie"/>
<property name="username" value="ralph"/> …
Run Code Online (Sandbox Code Playgroud) 我需要让MySQL服务器在客户端断开连接后立即回滚事务,因为每个客户端同时工作.问题可以像这些一样重复(使用innodb表类型)
在客户端A上:
START TRANSACTION;
SELECT MAX(ID) FROM tblone FOR UPDATE;
#... then disconnect your connection to the server
Run Code Online (Sandbox Code Playgroud)
在客户B上:
START TRANSACTION;
SELECT MAX(ID) FROM tblone FOR UPDATE;
#... lock wait time out will occur here
Run Code Online (Sandbox Code Playgroud)
我设置了MySQL的服务器选项,innodb_rollback_on_timeout
并mysql --skip-reconnect
在两个客户端上使用mysql的客户端.我在网络上尝试使用一台服务器和两台客户端.我在SELECT ... FOR UPDATE;
线路后物理断开网络(拔掉电缆).我需要让其他客户端能够立即使用tblone
事务(锁定它,更新它),并且为了实现这一点,我认为服务器应该在客户端A断开连接之后回滚客户端A的事务.
在终端中使用sql在我的PostgreSQL数据库中编辑一些记录时(在ubuntu lucid中),我做了一个错误的更新.
代替 -
update mytable set start_time='13:06:00' where id=123;
Run Code Online (Sandbox Code Playgroud)
我打字 -
update mytable set start_time='13:06:00';
Run Code Online (Sandbox Code Playgroud)
因此,所有记录现在具有相同的start_time值.
有没有办法撤消这种变化?表中有大约500条记录,我不知道每条记录的start_time值是多少
它会永远丢失吗?
在Visual Studio 2013 Update 3中,我意外地检查了一个未编译的,正在进行中的变更集,我打算将其搁置以供同事使用.我马上回滚了变更集.不好意思
有没有办法将这个糟糕/回滚的变更集恢复为待定变更,以便我(或我的同事)可以继续使用它?我没有在UI中看到任何内容,必须手动拉出每个文件并手动构建挂起的更改.最初编码它只需20分钟,所以没有那么大的交易(这是我的错误),但我很好奇是否有更好的方法.
当您使用Session-Per-Request模式时,您在使用NHibernate的3层应用程序中使用哪种模式/体系结构需要支持事务失败的重试?(因为ISession在异常后变为无效,即使这是死锁或超时或活锁异常).
鉴于以下迁移:
[Migration(1)]
public class Mig001 : Migration
{
public override void Up()
{
Alter.Table("foo").AlterColumn("bar").AsInt32().Nullable();
}
public override void Down()
{
Alter.Table("foo").AlterColumn("bar").AsInt32().NotNullable();
}
}
Run Code Online (Sandbox Code Playgroud)
迁移器更改列并使其可为空,并且在回滚时它会执行相反操作并使其不再可为空.
让我们说foo
自迁移以来已经添加了数据; 现在列中有null的bar
行.
如果它被回滚然后操作将失败,在fluentmigrator中是否有办法处理这种情况?或者什么是最佳实践.
rollback ×10
transactions ×3
c# ×1
deadlock ×1
disconnect ×1
ejb ×1
git ×1
git-amend ×1
git-revert ×1
java ×1
jdbc ×1
livelock ×1
mysql ×1
nhibernate ×1
nullable ×1
postgresql ×1
spring ×1
svn ×1
testing ×1
tfs ×1
timeout ×1
tortoisesvn ×1
undo ×1
web-services ×1