Skip to content
Snippets Groups Projects
Commit 06a98a92 authored by ichung14's avatar ichung14
Browse files

db change

parent 5154b6d1
No related branches found
No related tags found
No related merge requests found
Showing
with 344 additions and 42 deletions
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<option name="testRunner" value="GRADLE" /> <option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" /> <option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="jbr-11" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />
......
...@@ -68,11 +68,14 @@ ...@@ -68,11 +68,14 @@
</map> </map>
</option> </option>
</component> </component>
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android API 32 Platform" project-jdk-type="Android SDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android API 32 Platform" project-jdk-type="Android SDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
<option name="id" value="Android" /> <option name="id" value="jpab" />
</component> </component>
<component name="VisualizationToolProject"> <component name="VisualizationToolProject">
<option name="state"> <option name="state">
......
{
"formatVersion": 1,
"database": {
"version": 11,
"identityHash": "fd4a09888bcbd42b7c2df70db27d5a8f",
"entities": [
{
"tableName": "Note",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`title` TEXT NOT NULL, `content` TEXT NOT NULL, `notify` INTEGER NOT NULL, `folderId` INTEGER, `createdTime` INTEGER NOT NULL, `updatedTime` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, FOREIGN KEY(`folderId`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL )",
"fields": [
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "content",
"columnName": "content",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "notify",
"columnName": "notify",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "folderId",
"columnName": "folderId",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "createdTime",
"columnName": "createdTime",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "updatedTime",
"columnName": "updatedTime",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": [
{
"table": "Folder",
"onDelete": "SET NULL",
"onUpdate": "NO ACTION",
"columns": [
"folderId"
],
"referencedColumns": [
"id"
]
}
]
},
{
"tableName": "Folder",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `parent` INTEGER, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `createdTime` INTEGER NOT NULL, `updatedTime` INTEGER NOT NULL, FOREIGN KEY(`parent`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "parent",
"columnName": "parent",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "createdTime",
"columnName": "createdTime",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "updatedTime",
"columnName": "updatedTime",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": [
{
"table": "Folder",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"parent"
],
"referencedColumns": [
"id"
]
}
]
},
{
"tableName": "Tag",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `createdTime` INTEGER NOT NULL, `updatedTime` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "createdTime",
"columnName": "createdTime",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "updatedTime",
"columnName": "updatedTime",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [
{
"name": "index_Tag_name",
"unique": true,
"columnNames": [
"name"
],
"orders": [],
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_Tag_name` ON `${TABLE_NAME}` (`name`)"
}
],
"foreignKeys": []
},
{
"tableName": "TagNoteCrossRef",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`tagId` INTEGER NOT NULL, `noteId` INTEGER NOT NULL, `createdTime` INTEGER NOT NULL, `updatedTime` INTEGER NOT NULL, PRIMARY KEY(`tagId`, `noteId`), FOREIGN KEY(`tagId`) REFERENCES `Tag`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`noteId`) REFERENCES `Note`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "tagId",
"columnName": "tagId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "noteId",
"columnName": "noteId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "createdTime",
"columnName": "createdTime",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "updatedTime",
"columnName": "updatedTime",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"tagId",
"noteId"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": [
{
"table": "Tag",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"tagId"
],
"referencedColumns": [
"id"
]
},
{
"table": "Note",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"noteId"
],
"referencedColumns": [
"id"
]
}
]
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'fd4a09888bcbd42b7c2df70db27d5a8f')"
]
}
}
\ No newline at end of file
...@@ -7,6 +7,7 @@ import androidx.test.core.app.ApplicationProvider ...@@ -7,6 +7,7 @@ import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import com.noteapplication.cs398.database.*
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import org.junit.After import org.junit.After
......
...@@ -19,7 +19,11 @@ import androidx.lifecycle.ViewModelProvider ...@@ -19,7 +19,11 @@ import androidx.lifecycle.ViewModelProvider
import java.io.InputStream import java.io.InputStream
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.noteapplication.cs398.database.Folder
import com.noteapplication.cs398.database.Note
import com.noteapplication.cs398.database.Tag
import com.noteapplication.cs398.databinding.ActivityAddNoteBinding import com.noteapplication.cs398.databinding.ActivityAddNoteBinding
import java.util.*
class AddNoteActivity : AppCompatActivity() { class AddNoteActivity : AppCompatActivity() {
private lateinit var binding: ActivityAddNoteBinding private lateinit var binding: ActivityAddNoteBinding
...@@ -29,10 +33,8 @@ class AddNoteActivity : AppCompatActivity() { ...@@ -29,10 +33,8 @@ class AddNoteActivity : AppCompatActivity() {
private var title: String = "" private var title: String = ""
private var content: String = "" private var content: String = ""
private var todo: Boolean = false private var todo: Boolean = false
private var isEditing: Boolean = false
private var oldId: Long? = null private var oldNote: Note? = null
private var oldFolderId: Long? = null
private var folder: Folder? = null private var folder: Folder? = null
...@@ -55,13 +57,11 @@ class AddNoteActivity : AppCompatActivity() { ...@@ -55,13 +57,11 @@ class AddNoteActivity : AppCompatActivity() {
// set bindings // set bindings
binding = ActivityAddNoteBinding.inflate(layoutInflater) binding = ActivityAddNoteBinding.inflate(layoutInflater)
(intent.getSerializableExtra("note") as Note?)?.let { oldNote = intent.getSerializableExtra("note") as Note?
isEditing = true oldNote?.let {
binding.titleInput.setText(it.title) binding.titleInput.setText(it.title)
binding.contentInput.setText(it.content) binding.contentInput.setText(it.content)
binding.idRmdSwitch.isChecked = it.notify binding.idRmdSwitch.isChecked = it.notify
oldId = it.id
oldFolderId = it.folderId
tagViewModel.setCurrentSelectedTags(it.id) tagViewModel.setCurrentSelectedTags(it.id)
} }
...@@ -92,18 +92,16 @@ class AddNoteActivity : AppCompatActivity() { ...@@ -92,18 +92,16 @@ class AddNoteActivity : AppCompatActivity() {
val newNote: Note val newNote: Note
if(isEditing){ if (oldNote != null) {
newNote = Note( newNote = oldNote!!.copy(
binding.titleInput.text.toString(), title = binding.titleInput.text.toString(),
binding.contentInput.text.toString(), content = binding.contentInput.text.toString(),
binding.idRmdSwitch.isChecked, notify = binding.idRmdSwitch.isChecked,
oldFolderId, updatedTime = Date().time
id = oldId!!
) )
noteViewModel.updateNote(newNote, tagViewModel.getSelectedTags()) noteViewModel.updateNote(newNote, tagViewModel.getSelectedTags())
} else {
}else{ newNote = Note(
newNote = Note(
binding.titleInput.text.toString(), binding.titleInput.text.toString(),
binding.contentInput.text.toString(), binding.contentInput.text.toString(),
binding.idRmdSwitch.isChecked, binding.idRmdSwitch.isChecked,
......
...@@ -8,6 +8,7 @@ import android.view.View ...@@ -8,6 +8,7 @@ import android.view.View
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.noteapplication.cs398.database.Folder
import com.noteapplication.cs398.databinding.ActivityFolderBinding import com.noteapplication.cs398.databinding.ActivityFolderBinding
......
...@@ -5,6 +5,7 @@ import android.view.LayoutInflater ...@@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.noteapplication.cs398.database.Folder
import com.noteapplication.cs398.databinding.CourseItemBinding import com.noteapplication.cs398.databinding.CourseItemBinding
class FolderListAdapter(private val viewModel: FolderViewModel, private val activity: AppCompatActivity) : class FolderListAdapter(private val viewModel: FolderViewModel, private val activity: AppCompatActivity) :
......
...@@ -4,6 +4,9 @@ import android.app.Application ...@@ -4,6 +4,9 @@ import android.app.Application
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.noteapplication.cs398.database.Folder
import com.noteapplication.cs398.database.NoteDataAccess
import com.noteapplication.cs398.database.NoteDatabase
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
......
package com.noteapplication.cs398 package com.noteapplication.cs398
import android.app.Activity
import android.content.Context
import android.content.Intent import android.content.Intent
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat.startActivity
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.noteapplication.cs398.database.Note
import com.noteapplication.cs398.databinding.NoteItemBinding import com.noteapplication.cs398.databinding.NoteItemBinding
class ListAdapter(private val viewModel: NoteViewModel, private val activity: AppCompatActivity) : class ListAdapter(private val viewModel: NoteViewModel, private val activity: AppCompatActivity) :
......
...@@ -8,6 +8,7 @@ import android.view.View ...@@ -8,6 +8,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.noteapplication.cs398.database.Folder
import com.noteapplication.cs398.databinding.BottomSheetNewFolderBinding import com.noteapplication.cs398.databinding.BottomSheetNewFolderBinding
class NewFolderBottomSheet(private var viewModel: FolderViewModel) : BottomSheetDialogFragment() { class NewFolderBottomSheet(private var viewModel: FolderViewModel) : BottomSheetDialogFragment() {
......
...@@ -2,6 +2,7 @@ package com.noteapplication.cs398 ...@@ -2,6 +2,7 @@ package com.noteapplication.cs398
import android.app.Application import android.app.Application
import androidx.lifecycle.* import androidx.lifecycle.*
import com.noteapplication.cs398.database.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
......
...@@ -7,10 +7,10 @@ import android.os.Bundle ...@@ -7,10 +7,10 @@ import android.os.Bundle
import android.view.View import android.view.View
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.noteapplication.cs398.database.Note
import com.noteapplication.cs398.databinding.ActivityReadNoteBinding import com.noteapplication.cs398.databinding.ActivityReadNoteBinding
class ReadNoteActivity : AppCompatActivity(){ class ReadNoteActivity : AppCompatActivity(){
......
package com.noteapplication.cs398 package com.noteapplication.cs398
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat.startActivity
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.noteapplication.cs398.databinding.CourseItemBinding import com.noteapplication.cs398.database.Tag
import com.noteapplication.cs398.databinding.NoteItemBinding
import com.noteapplication.cs398.databinding.TagItemBinding import com.noteapplication.cs398.databinding.TagItemBinding
class TagListAdapter( class TagListAdapter(
......
...@@ -4,6 +4,9 @@ import android.app.Application ...@@ -4,6 +4,9 @@ import android.app.Application
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.noteapplication.cs398.database.NoteDataAccess
import com.noteapplication.cs398.database.NoteDatabase
import com.noteapplication.cs398.database.Tag
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
......
package com.noteapplication.cs398 package com.noteapplication.cs398.database
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.room.* import androidx.room.*
import java.text.SimpleDateFormat
import java.util.*
@Dao @Dao
interface NoteDataAccess { interface NoteDataAccess {
@Insert(onConflict = OnConflictStrategy.IGNORE, entity = Note::class) @Insert(onConflict = OnConflictStrategy.IGNORE, entity = Note::class)
suspend fun insert(note:Note): Long suspend fun insert(note: Note): Long
@Insert(onConflict = OnConflictStrategy.IGNORE, entity = Folder::class) @Insert(onConflict = OnConflictStrategy.IGNORE, entity = Folder::class)
suspend fun insert(folder: Folder): Long suspend fun insert(folder: Folder): Long
...@@ -18,7 +20,7 @@ interface NoteDataAccess { ...@@ -18,7 +20,7 @@ interface NoteDataAccess {
suspend fun insert(tagNoteCrossRef: TagNoteCrossRef) suspend fun insert(tagNoteCrossRef: TagNoteCrossRef)
@Update(entity = Note::class) @Update(entity = Note::class)
suspend fun update(note:Note) suspend fun update(note: Note)
@Update(entity = Folder::class) @Update(entity = Folder::class)
suspend fun update(folder: Folder) suspend fun update(folder: Folder)
...@@ -106,4 +108,8 @@ interface NoteDataAccess { ...@@ -106,4 +108,8 @@ interface NoteDataAccess {
"delete from TagNoteCrossRef where noteId = :noteId" "delete from TagNoteCrossRef where noteId = :noteId"
) )
suspend fun deleteAllTags(noteId: Long) suspend fun deleteAllTags(noteId: Long)
} }
\ No newline at end of file
fun Long.toDateString(): String{
return SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.CANADA).format(Date(this))
}
package com.noteapplication.cs398 package com.noteapplication.cs398.database
import android.content.Context import android.content.Context
import androidx.room.* import androidx.room.*
import androidx.room.migration.AutoMigrationSpec
@Database(entities = [Note::class, Folder::class, Tag::class, TagNoteCrossRef::class], version = 10) @Database(entities = [Note::class, Folder::class, Tag::class, TagNoteCrossRef::class], version = 11)
abstract class NoteDatabase : RoomDatabase() { abstract class NoteDatabase : RoomDatabase() {
abstract fun getNoteDataAccess(): NoteDataAccess abstract fun getNoteDataAccess(): NoteDataAccess
...@@ -12,7 +11,7 @@ abstract class NoteDatabase : RoomDatabase() { ...@@ -12,7 +11,7 @@ abstract class NoteDatabase : RoomDatabase() {
@Volatile @Volatile
private var INSTANCE: NoteDatabase? = null private var INSTANCE: NoteDatabase? = null
fun getDatabase(context: Context): NoteDatabase{ fun getDatabase(context: Context): NoteDatabase {
return INSTANCE ?: synchronized(this){ return INSTANCE ?: synchronized(this){
val instance = Room.databaseBuilder( val instance = Room.databaseBuilder(
context.applicationContext, context.applicationContext,
......
package com.noteapplication.cs398 package com.noteapplication.cs398.database
import androidx.room.* import androidx.room.*
import java.io.Serializable import java.io.Serializable
...@@ -18,8 +18,8 @@ data class Note ( ...@@ -18,8 +18,8 @@ data class Note (
@ColumnInfo(name = "content") val content:String, @ColumnInfo(name = "content") val content:String,
@ColumnInfo(name = "notify") val notify:Boolean, @ColumnInfo(name = "notify") val notify:Boolean,
@ColumnInfo(name = "folderId") val folderId:Long?, @ColumnInfo(name = "folderId") val folderId:Long?,
@ColumnInfo(name = "createdTime") val createdTime:String = @ColumnInfo(name = "createdTime") val createdTime:Long = Date().time,
SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.CANADA).format(Date()), @ColumnInfo(name = "updatedTime") val updatedTime:Long = Date().time,
@PrimaryKey(autoGenerate = true) var id: Long = 0, @PrimaryKey(autoGenerate = true) var id: Long = 0,
): Serializable ): Serializable
...@@ -34,7 +34,9 @@ data class Note ( ...@@ -34,7 +34,9 @@ data class Note (
data class Folder ( data class Folder (
@ColumnInfo(name = "name") val name:String, @ColumnInfo(name = "name") val name:String,
@ColumnInfo(name = "parent") val parent:Long? = null, @ColumnInfo(name = "parent") val parent:Long? = null,
@PrimaryKey(autoGenerate = true) var id: Long = 0 @PrimaryKey(autoGenerate = true) var id: Long = 0,
@ColumnInfo(name = "createdTime") val createdTime:Long = Date().time,
@ColumnInfo(name = "updatedTime") val updatedTime:Long = Date().time,
): Serializable ): Serializable
@Entity(tableName = "Tag", @Entity(tableName = "Tag",
...@@ -45,7 +47,9 @@ data class Folder ( ...@@ -45,7 +47,9 @@ data class Folder (
) )
data class Tag ( data class Tag (
@ColumnInfo(name = "name") val name:String, @ColumnInfo(name = "name") val name:String,
@PrimaryKey(autoGenerate = true) var id: Long = 0 @PrimaryKey(autoGenerate = true) var id: Long = 0,
@ColumnInfo(name = "createdTime") val createdTime:Long = Date().time,
@ColumnInfo(name = "updatedTime") val updatedTime:Long = Date().time,
) )
@Entity(tableName = "TagNoteCrossRef", @Entity(tableName = "TagNoteCrossRef",
...@@ -67,5 +71,7 @@ data class Tag ( ...@@ -67,5 +71,7 @@ data class Tag (
) )
data class TagNoteCrossRef ( data class TagNoteCrossRef (
val tagId:Long, val tagId:Long,
val noteId:Long val noteId:Long,
@ColumnInfo(name = "createdTime") val createdTime:Long = Date().time,
@ColumnInfo(name = "updatedTime") val updatedTime:Long = Date().time,
) )
\ No newline at end of file
CREATE TABLE IF NOT EXISTS `Note`
(
`title` TEXT NOT NULL,
`content` TEXT NOT NULL,
`notify` INTEGER NOT NULL,
`folderId` INTEGER,
`createdTime` DATE NOT NULL,
`updatedTime` DATE NOT NULL,
`id` INTEGER NOT NULL,
FOREIGN KEY(`folderId`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL
)
CREATE TABLE IF NOT EXISTS `Folder`
(
`name` TEXT NOT NULL,
`parent` INTEGER,
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
`createdTime` DATE NOT NULL,
`updatedTime` DATE NOT NULL,
FOREIGN KEY(`parent`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE
)
CREATE TABLE IF NOT EXISTS `Tag`
(
`name` TEXT NOT NULL,
`createdTime` DATE NOT NULL,
`updatedTime` DATE NOT NULL,
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
)
CREATE TABLE IF NOT EXISTS `TagNoteCrossRef`
(
`tagId` INTEGER NOT NULL,
`noteId` INTEGER NOT NULL,
`createdTime` DATE NOT NULL,
`updatedTime` DATE NOT NULL,
PRIMARY KEY(`tagId`, `noteId`),
FOREIGN KEY(`tagId`) REFERENCES `Tag`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE,
FOREIGN KEY(`noteId`) REFERENCES `Note`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE
)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment