mirror of
https://github.com/OtusTeam/Spring.git
synced 2026-05-30 10:50:42 +00:00
migrations example updated
This commit is contained in:
@@ -11,12 +11,15 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.0.RELEASE</version>
|
||||
<version>3.1.3</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<h2.version>2.2.220</h2.version>
|
||||
<snakeyaml.version>2.0</snakeyaml.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -36,6 +39,11 @@
|
||||
<version>${h2.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>${snakeyaml.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
|
||||
+7
-7
@@ -16,8 +16,13 @@ public class AddUsersToCoursesReferenceTable implements JavaMigration {
|
||||
DataSource ds = new SingleConnectionDataSource(context.getConnection(), true);
|
||||
JdbcOperations jdbc = new JdbcTemplate(ds);
|
||||
|
||||
jdbc.execute("create table users_courses(user_id bigint references users(id), " +
|
||||
"course_id bigint references courses(id))");
|
||||
jdbc.execute("""
|
||||
CREATE TABLE users_courses (
|
||||
user_id bigint REFERENCES users(id),
|
||||
course_id bigint REFERENCES courses(id),
|
||||
PRIMARY KEY(user_id, course_id)
|
||||
)
|
||||
""");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,11 +40,6 @@ public class AddUsersToCoursesReferenceTable implements JavaMigration {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUndo() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExecuteInTransaction() {
|
||||
return true;
|
||||
|
||||
+8
-1
@@ -14,6 +14,13 @@ public class V3_1__2020_05_26_Add_courses_table extends BaseJavaMigration {
|
||||
public void migrate(Context context) throws Exception {
|
||||
DataSource ds = new SingleConnectionDataSource(context.getConnection(), true);
|
||||
JdbcOperations jdbc = new JdbcTemplate(ds);
|
||||
jdbc.execute("create table courses(id bigserial, name varchar(255))");
|
||||
|
||||
jdbc.execute("""
|
||||
create table courses (
|
||||
id bigserial,
|
||||
name varchar(255),
|
||||
primary key(id)
|
||||
)
|
||||
""");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
public class AppConfig {
|
||||
|
||||
+6
-1
@@ -1,4 +1,9 @@
|
||||
--date: 2019-01-11
|
||||
--author: ydvorzhetskiy
|
||||
|
||||
create table users (id bigserial, login varchar(50), password varchar(50))
|
||||
create table users (
|
||||
id bigserial,
|
||||
login varchar(50),
|
||||
password varchar(50),
|
||||
primary key(id)
|
||||
)
|
||||
+2
-1
@@ -4,5 +4,6 @@
|
||||
create table emails (
|
||||
id bigserial,
|
||||
user_id bigint references users(id) ON DELETE CASCADE,
|
||||
email varchar(50)
|
||||
email varchar(50),
|
||||
primary key(id)
|
||||
)
|
||||
+1
-1
@@ -6,5 +6,5 @@ values (1, 'Разработчик Java'),
|
||||
|
||||
insert into users_courses (user_id, course_id)
|
||||
values (1, 1), (1, 2), (1, 3), (1, 4),
|
||||
(2, 1), (2, 2), (1, 3),
|
||||
(2, 1), (2, 2), (2, 3),
|
||||
(3, 3), (3, 4);
|
||||
@@ -11,12 +11,15 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.0.RELEASE</version>
|
||||
<version>3.1.3</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<h2.version>2.2.220</h2.version>
|
||||
<snakeyaml.version>2.0</snakeyaml.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -30,6 +33,12 @@
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>${snakeyaml.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user