A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

111 lines
2.2 KiB

  1. /*
  2. * Copyright © 2019 Musing Studio LLC.
  3. *
  4. * This file is part of WriteFreely.
  5. *
  6. * WriteFreely is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License, included
  8. * in the LICENSE file in this source code package.
  9. */
  10. package migrations
  11. import (
  12. "fmt"
  13. )
  14. // TODO: use now() from writefreely pkg
  15. func (db *datastore) now() string {
  16. if db.driverName == driverSQLite {
  17. return "strftime('%Y-%m-%d %H:%M:%S','now')"
  18. }
  19. return "NOW()"
  20. }
  21. func (db *datastore) typeInt() string {
  22. if db.driverName == driverSQLite {
  23. return "INTEGER"
  24. }
  25. return "INT"
  26. }
  27. func (db *datastore) typeSmallInt() string {
  28. if db.driverName == driverSQLite {
  29. return "INTEGER"
  30. }
  31. return "SMALLINT"
  32. }
  33. func (db *datastore) typeTinyInt() string {
  34. if db.driverName == driverSQLite {
  35. return "INTEGER"
  36. }
  37. return "TINYINT"
  38. }
  39. func (db *datastore) typeText() string {
  40. return "TEXT"
  41. }
  42. func (db *datastore) typeChar(l int) string {
  43. if db.driverName == driverSQLite {
  44. return "TEXT"
  45. }
  46. return fmt.Sprintf("CHAR(%d)", l)
  47. }
  48. func (db *datastore) typeVarChar(l int) string {
  49. if db.driverName == driverSQLite {
  50. return "TEXT"
  51. }
  52. return fmt.Sprintf("VARCHAR(%d)", l)
  53. }
  54. func (db *datastore) typeVarBinary(l int) string {
  55. if db.driverName == driverSQLite {
  56. return "BLOB"
  57. }
  58. return fmt.Sprintf("VARBINARY(%d)", l)
  59. }
  60. func (db *datastore) typeBool() string {
  61. if db.driverName == driverSQLite {
  62. return "INTEGER"
  63. }
  64. return "TINYINT(1)"
  65. }
  66. func (db *datastore) typeDateTime() string {
  67. return "DATETIME"
  68. }
  69. func (db *datastore) typeIntPrimaryKey() string {
  70. if db.driverName == driverSQLite {
  71. // From docs: "In SQLite, a column with type INTEGER PRIMARY KEY is an alias for the ROWID (except in WITHOUT
  72. // ROWID tables) which is always a 64-bit signed integer."
  73. return "INTEGER PRIMARY KEY"
  74. }
  75. return "INT AUTO_INCREMENT PRIMARY KEY"
  76. }
  77. func (db *datastore) collateMultiByte() string {
  78. if db.driverName == driverSQLite {
  79. return ""
  80. }
  81. return " COLLATE utf8_bin"
  82. }
  83. func (db *datastore) engine() string {
  84. if db.driverName == driverSQLite {
  85. return ""
  86. }
  87. return " ENGINE = InnoDB"
  88. }
  89. func (db *datastore) after(colName string) string {
  90. if db.driverName == driverSQLite {
  91. return ""
  92. }
  93. return " AFTER " + colName
  94. }