|
1 | 1 | package lib.db |
2 | 2 |
|
| 3 | +import com.typesafe.scalalogging.StrictLogging |
| 4 | +import lib.{App, AppVersion} |
3 | 5 | import scalikejdbc._ |
4 | 6 |
|
5 | 7 | //noinspection SqlNoDataSourceInspection |
6 | | -object DbScheme { |
| 8 | +object DbScheme extends StrictLogging { |
7 | 9 | def create(implicit session: DBSession): Unit = { |
| 10 | + val currentVersionStr = App.versionStr |
| 11 | + |
8 | 12 | sql""" |
9 | 13 | |CREATE TABLE IF NOT EXISTS FILES |
10 | 14 | |( |
@@ -40,16 +44,26 @@ object DbScheme { |
40 | 44 | |); |
41 | 45 | | |
42 | 46 | """.stripMargin.executeUpdate().apply() |
| 47 | + |
| 48 | + if (App.version > AppVersion(0, 1, 3)) { |
| 49 | + if (sql"""select value from settings where key='db_version'""".map(_.string("value")).single().apply().isEmpty) { |
| 50 | + logger.info(s"Didn't found db_version in DB, setting to $currentVersionStr") |
| 51 | + |
| 52 | + sql""" |
| 53 | + |insert ignore into settings values ('db_version', ${currentVersionStr}); |
| 54 | + """.stripMargin.executeUpdate().apply() |
| 55 | + } |
| 56 | + } |
43 | 57 | } |
44 | 58 |
|
45 | | - def truncateAll(implicit session: DBSession): Unit = { |
| 59 | + def dropAll(implicit session: DBSession): Unit = { |
46 | 60 | sql""" |
47 | 61 | |SET REFERENTIAL_INTEGRITY FALSE; |
48 | 62 | | |
49 | | - |truncate table files; |
50 | | - |truncate table settings; |
51 | | - |truncate table backup_sets; |
52 | | - |truncate table backup_sets_files; |
| 63 | + |drop table if exists files; |
| 64 | + |drop table if exists settings; |
| 65 | + |drop table if exists backup_sets; |
| 66 | + |drop table if exists backup_sets_files; |
53 | 67 | | |
54 | 68 | |SET REFERENTIAL_INTEGRITY TRUE; |
55 | 69 | """.stripMargin.executeUpdate().apply() |
|
0 commit comments