create-lx2-app 0.7.2 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/index.js +27 -24
- package/package.json +1 -1
- package/template/packages/config/drizzle/with-mysql.ts +12 -0
- package/template/packages/config/drizzle/with-postgres.ts +12 -0
- package/template/packages/config/drizzle/with-sqlite.ts +12 -0
- package/template/packages/src/app/page/base.tsx +2 -2
- package/template/packages/src/app/page/with-authjs-drizzle.tsx +222 -0
- package/template/packages/src/app/page/with-authjs-prisma.tsx +2 -2
- package/template/packages/src/app/page/with-authjs.tsx +2 -2
- package/template/packages/src/app/page/with-better-auth-drizzle.tsx +234 -0
- package/template/packages/src/app/page/with-better-auth-prisma.tsx +2 -2
- package/template/packages/src/app/page/with-better-auth.tsx +2 -2
- package/template/packages/src/app/page/with-drizzle.tsx +172 -0
- package/template/packages/src/app/page/with-payload.tsx +2 -4
- package/template/packages/src/app/page/with-prisma.tsx +2 -2
- package/template/packages/src/server/auth/config/authjs-with-drizzle.ts +51 -0
- package/template/packages/src/server/auth/config/better-auth-with-prisma.ts +1 -0
- package/template/packages/src/server/db/index-drizzle/with-mysql.ts +19 -0
- package/template/packages/src/server/db/index-drizzle/with-postgres.ts +19 -0
- package/template/packages/src/server/db/index-drizzle/with-sqlite.ts +20 -0
- package/template/packages/src/server/db/schema-drizzle/base-mysql.ts +27 -0
- package/template/packages/src/server/db/schema-drizzle/base-postgres.ts +27 -0
- package/template/packages/src/server/db/schema-drizzle/base-sqlite.ts +27 -0
- package/template/packages/src/server/db/schema-drizzle/with-authjs-mysql.ts +138 -0
- package/template/packages/src/server/db/schema-drizzle/with-authjs-postgres.ts +138 -0
- package/template/packages/src/server/db/schema-drizzle/with-authjs-sqlite.ts +138 -0
- package/template/packages/src/server/db/schema-drizzle/with-better-auth-mysql.ts +113 -0
- package/template/packages/src/server/db/schema-drizzle/with-better-auth-postgres.ts +113 -0
- package/template/packages/src/server/db/schema-drizzle/with-better-auth-sqlite.ts +113 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// This is an example schema for PostgreSQL using Drizzle ORM.
|
|
2
|
+
// Learn more at https://orm.drizzle.team/docs/sql-schema-declaration
|
|
3
|
+
|
|
4
|
+
import { sql } from "drizzle-orm"
|
|
5
|
+
import { index, mysqlTableCreator, primaryKey } from "drizzle-orm/mysql-core"
|
|
6
|
+
import { type AdapterAccountType } from "next-auth/adapters"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Below is an example of how to create a table with a prefix.
|
|
10
|
+
* This is useful for multi-tenant applications where you want to separate data by tenant.
|
|
11
|
+
*
|
|
12
|
+
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
|
|
13
|
+
*/
|
|
14
|
+
export const createTable = mysqlTableCreator((name) => `project1_${name}`)
|
|
15
|
+
|
|
16
|
+
export const post = createTable(
|
|
17
|
+
"post",
|
|
18
|
+
(d) => ({
|
|
19
|
+
id: d.bigint({ mode: "number" }).primaryKey().autoincrement(),
|
|
20
|
+
name: d.varchar({ length: 255 }).notNull(),
|
|
21
|
+
createdAt: d
|
|
22
|
+
.timestamp({ mode: "date" })
|
|
23
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
24
|
+
.notNull(),
|
|
25
|
+
updatedAt: d.timestamp({ mode: "date" }).$onUpdate(() => new Date()),
|
|
26
|
+
}),
|
|
27
|
+
(t) => [index("post_name_idx").on(t.name)]
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
export const user = createTable(
|
|
31
|
+
"user",
|
|
32
|
+
(d) => ({
|
|
33
|
+
id: d
|
|
34
|
+
.varchar({ length: 255 })
|
|
35
|
+
.primaryKey()
|
|
36
|
+
.$defaultFn(() => crypto.randomUUID()),
|
|
37
|
+
name: d.varchar({ length: 255 }).notNull(),
|
|
38
|
+
email: d.varchar({ length: 255 }).notNull().unique(),
|
|
39
|
+
emailVerified: d.timestamp({ mode: "date", fsp: 3 }),
|
|
40
|
+
image: d.varchar({ length: 255 }),
|
|
41
|
+
createdAt: d
|
|
42
|
+
.timestamp({ mode: "date" })
|
|
43
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
44
|
+
.notNull(),
|
|
45
|
+
updatedAt: d.timestamp({ mode: "date" }).$onUpdate(() => new Date()),
|
|
46
|
+
}),
|
|
47
|
+
(t) => [
|
|
48
|
+
index("user_name_idx").on(t.name),
|
|
49
|
+
index("user_email_idx").on(t.email),
|
|
50
|
+
]
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
export const session = createTable(
|
|
54
|
+
"session",
|
|
55
|
+
(d) => ({
|
|
56
|
+
sessionToken: d.varchar({ length: 255 }).primaryKey(),
|
|
57
|
+
userId: d
|
|
58
|
+
.varchar({ length: 255 })
|
|
59
|
+
.notNull()
|
|
60
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
61
|
+
expires: d.timestamp().notNull(),
|
|
62
|
+
createdAt: d
|
|
63
|
+
.timestamp({ mode: "date" })
|
|
64
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
65
|
+
.notNull(),
|
|
66
|
+
updatedAt: d.timestamp({ mode: "date" }).$onUpdate(() => new Date()),
|
|
67
|
+
}),
|
|
68
|
+
(t) => [index("session_userId_idx").on(t.userId)]
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
export const account = createTable(
|
|
72
|
+
"account",
|
|
73
|
+
(d) => ({
|
|
74
|
+
provider: d.varchar({ length: 255 }).notNull(),
|
|
75
|
+
providerAccountId: d.varchar({ length: 255 }).notNull(),
|
|
76
|
+
id_token: d.varchar({ length: 2048 }),
|
|
77
|
+
scope: d.varchar({ length: 255 }),
|
|
78
|
+
password: d.text(),
|
|
79
|
+
type: d.varchar({ length: 255 }).$type<AdapterAccountType>().notNull(),
|
|
80
|
+
token_type: d.varchar({ length: 255 }),
|
|
81
|
+
session_state: d.varchar({ length: 255 }),
|
|
82
|
+
access_token: d.varchar({ length: 255 }),
|
|
83
|
+
refresh_token: d.varchar({ length: 255 }),
|
|
84
|
+
userId: d
|
|
85
|
+
.varchar({ length: 255 })
|
|
86
|
+
.notNull()
|
|
87
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
88
|
+
expires_at: d.int(),
|
|
89
|
+
createdAt: d
|
|
90
|
+
.timestamp({ mode: "date" })
|
|
91
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
92
|
+
.notNull(),
|
|
93
|
+
updatedAt: d.timestamp({ mode: "date" }).$onUpdate(() => new Date()),
|
|
94
|
+
}),
|
|
95
|
+
(t) => [
|
|
96
|
+
index("account_userId_idx").on(t.userId),
|
|
97
|
+
primaryKey({ columns: [t.provider, t.providerAccountId] }),
|
|
98
|
+
]
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
export const verificationToken = createTable(
|
|
102
|
+
"verificationToken",
|
|
103
|
+
(d) => ({
|
|
104
|
+
identifier: d.varchar({ length: 255 }).notNull(),
|
|
105
|
+
token: d.varchar({ length: 255 }).notNull(),
|
|
106
|
+
expires: d.timestamp().notNull(),
|
|
107
|
+
createdAt: d
|
|
108
|
+
.timestamp({ mode: "date" })
|
|
109
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
110
|
+
.notNull(),
|
|
111
|
+
updatedAt: d.timestamp({ mode: "date" }).$onUpdate(() => new Date()),
|
|
112
|
+
}),
|
|
113
|
+
(t) => [
|
|
114
|
+
index("verification_identifier_idx").on(t.identifier),
|
|
115
|
+
primaryKey({ columns: [t.identifier, t.token] }),
|
|
116
|
+
]
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
export const authenticator = createTable(
|
|
120
|
+
"authenticator",
|
|
121
|
+
(d) => ({
|
|
122
|
+
counter: d.int().notNull(),
|
|
123
|
+
transports: d.varchar({ length: 255 }),
|
|
124
|
+
credentialID: d.varchar({ length: 255 }).notNull().unique(),
|
|
125
|
+
credentialPublicKey: d.varchar({ length: 255 }).notNull(),
|
|
126
|
+
credentialDeviceType: d.varchar({ length: 255 }).notNull(),
|
|
127
|
+
credentialBackedUp: d.boolean().notNull(),
|
|
128
|
+
providerAccountId: d.varchar({ length: 255 }).notNull(),
|
|
129
|
+
userId: d
|
|
130
|
+
.varchar({ length: 255 })
|
|
131
|
+
.notNull()
|
|
132
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
133
|
+
}),
|
|
134
|
+
(t) => [
|
|
135
|
+
index("authenticator_userId_idx").on(t.userId),
|
|
136
|
+
primaryKey({ columns: [t.userId, t.credentialID] }),
|
|
137
|
+
]
|
|
138
|
+
)
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// This is an example schema for PostgreSQL using Drizzle ORM.
|
|
2
|
+
// Learn more at https://orm.drizzle.team/docs/sql-schema-declaration
|
|
3
|
+
|
|
4
|
+
import { sql } from "drizzle-orm"
|
|
5
|
+
import { index, pgTableCreator, primaryKey } from "drizzle-orm/pg-core"
|
|
6
|
+
import { AdapterAccountType } from "next-auth/adapters"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Below is an example of how to create a table with a prefix.
|
|
10
|
+
* This is useful for multi-tenant applications where you want to separate data by tenant.
|
|
11
|
+
*
|
|
12
|
+
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
|
|
13
|
+
*/
|
|
14
|
+
export const createTable = pgTableCreator((name) => `project1_${name}`)
|
|
15
|
+
|
|
16
|
+
export const post = createTable(
|
|
17
|
+
"post",
|
|
18
|
+
(d) => ({
|
|
19
|
+
id: d.integer().primaryKey().generatedByDefaultAsIdentity(),
|
|
20
|
+
name: d.varchar({ length: 255 }).notNull(),
|
|
21
|
+
createdAt: d
|
|
22
|
+
.timestamp({ withTimezone: true })
|
|
23
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
24
|
+
.notNull(),
|
|
25
|
+
updatedAt: d.timestamp({ withTimezone: true }).$onUpdate(() => new Date()),
|
|
26
|
+
}),
|
|
27
|
+
(t) => [index("post_name_idx").on(t.name)]
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
export const user = createTable(
|
|
31
|
+
"user",
|
|
32
|
+
(d) => ({
|
|
33
|
+
id: d
|
|
34
|
+
.text()
|
|
35
|
+
.primaryKey()
|
|
36
|
+
.$defaultFn(() => crypto.randomUUID()),
|
|
37
|
+
name: d.text(),
|
|
38
|
+
email: d.text().unique(),
|
|
39
|
+
emailVerified: d.timestamp({ withTimezone: true }),
|
|
40
|
+
image: d.text(),
|
|
41
|
+
createdAt: d
|
|
42
|
+
.timestamp({ withTimezone: true })
|
|
43
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
44
|
+
.notNull(),
|
|
45
|
+
updatedAt: d.timestamp({ withTimezone: true }).$onUpdate(() => new Date()),
|
|
46
|
+
}),
|
|
47
|
+
(t) => [
|
|
48
|
+
index("user_name_idx").on(t.name),
|
|
49
|
+
index("user_email_idx").on(t.email),
|
|
50
|
+
]
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
export const session = createTable(
|
|
54
|
+
"session",
|
|
55
|
+
(d) => ({
|
|
56
|
+
sessionToken: d.text().primaryKey(),
|
|
57
|
+
userId: d
|
|
58
|
+
.text()
|
|
59
|
+
.notNull()
|
|
60
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
61
|
+
expires: d.timestamp({ withTimezone: true }).notNull(),
|
|
62
|
+
createdAt: d
|
|
63
|
+
.timestamp({ withTimezone: true })
|
|
64
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
65
|
+
.notNull(),
|
|
66
|
+
updatedAt: d.timestamp({ withTimezone: true }).$onUpdate(() => new Date()),
|
|
67
|
+
}),
|
|
68
|
+
(t) => [index("session_userId_idx").on(t.userId)]
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
export const account = createTable(
|
|
72
|
+
"account",
|
|
73
|
+
(d) => ({
|
|
74
|
+
provider: d.text().notNull(),
|
|
75
|
+
providerAccountId: d.text().notNull(),
|
|
76
|
+
id_token: d.text(),
|
|
77
|
+
scope: d.text(),
|
|
78
|
+
password: d.text(),
|
|
79
|
+
type: d.text().$type<AdapterAccountType>().notNull(),
|
|
80
|
+
token_type: d.text(),
|
|
81
|
+
session_state: d.text(),
|
|
82
|
+
access_token: d.text(),
|
|
83
|
+
refresh_token: d.text(),
|
|
84
|
+
expires_at: d.integer(),
|
|
85
|
+
userId: d
|
|
86
|
+
.text()
|
|
87
|
+
.notNull()
|
|
88
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
89
|
+
createdAt: d
|
|
90
|
+
.timestamp({ withTimezone: true })
|
|
91
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
92
|
+
.notNull(),
|
|
93
|
+
updatedAt: d.timestamp({ withTimezone: true }).$onUpdate(() => new Date()),
|
|
94
|
+
}),
|
|
95
|
+
(t) => [
|
|
96
|
+
index("account_userId_idx").on(t.userId),
|
|
97
|
+
primaryKey({ columns: [t.provider, t.providerAccountId] }),
|
|
98
|
+
]
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
export const verificationToken = createTable(
|
|
102
|
+
"verificationToken",
|
|
103
|
+
(d) => ({
|
|
104
|
+
identifier: d.text().notNull(),
|
|
105
|
+
token: d.text().notNull(),
|
|
106
|
+
expires: d.timestamp({ withTimezone: true }).notNull(),
|
|
107
|
+
createdAt: d
|
|
108
|
+
.timestamp({ withTimezone: true })
|
|
109
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
110
|
+
.notNull(),
|
|
111
|
+
updatedAt: d.timestamp({ withTimezone: true }).$onUpdate(() => new Date()),
|
|
112
|
+
}),
|
|
113
|
+
(t) => [
|
|
114
|
+
index("verification_identifier_idx").on(t.identifier),
|
|
115
|
+
primaryKey({ columns: [t.identifier, t.token] }),
|
|
116
|
+
]
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
export const authenticator = createTable(
|
|
120
|
+
"authenticator",
|
|
121
|
+
(d) => ({
|
|
122
|
+
counter: d.integer().notNull(),
|
|
123
|
+
transports: d.text(),
|
|
124
|
+
credentialID: d.text().notNull().unique(),
|
|
125
|
+
credentialPublicKey: d.text().notNull(),
|
|
126
|
+
credentialDeviceType: d.text().notNull(),
|
|
127
|
+
credentialBackedUp: d.boolean().notNull(),
|
|
128
|
+
providerAccountId: d.text().notNull(),
|
|
129
|
+
userId: d
|
|
130
|
+
.text("userId")
|
|
131
|
+
.notNull()
|
|
132
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
133
|
+
}),
|
|
134
|
+
(t) => [
|
|
135
|
+
index("authenticator_userId_idx").on(t.userId),
|
|
136
|
+
primaryKey({ columns: [t.userId, t.credentialID] }),
|
|
137
|
+
]
|
|
138
|
+
)
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// This is an example schema for PostgreSQL using Drizzle ORM.
|
|
2
|
+
// Learn more at https://orm.drizzle.team/docs/sql-schema-declaration
|
|
3
|
+
|
|
4
|
+
import { sql } from "drizzle-orm"
|
|
5
|
+
import { index, primaryKey, sqliteTableCreator } from "drizzle-orm/sqlite-core"
|
|
6
|
+
import { type AdapterAccountType } from "next-auth/adapters"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Below is an example of how to create a table with a prefix.
|
|
10
|
+
* This is useful for multi-tenant applications where you want to separate data by tenant.
|
|
11
|
+
*
|
|
12
|
+
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
|
|
13
|
+
*/
|
|
14
|
+
export const createTable = sqliteTableCreator((name) => `project1_${name}`)
|
|
15
|
+
|
|
16
|
+
export const post = createTable(
|
|
17
|
+
"post",
|
|
18
|
+
(d) => ({
|
|
19
|
+
id: d.integer({ mode: "number" }).primaryKey({ autoIncrement: true }),
|
|
20
|
+
name: d.text({ length: 255 }).notNull(),
|
|
21
|
+
createdAt: d
|
|
22
|
+
.integer({ mode: "timestamp" })
|
|
23
|
+
.default(sql`(unixepoch())`)
|
|
24
|
+
.notNull(),
|
|
25
|
+
updatedAt: d.integer({ mode: "timestamp" }).$onUpdate(() => new Date()),
|
|
26
|
+
}),
|
|
27
|
+
(t) => [index("post_name_idx").on(t.name)]
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
export const user = createTable(
|
|
31
|
+
"user",
|
|
32
|
+
(d) => ({
|
|
33
|
+
id: d
|
|
34
|
+
.text()
|
|
35
|
+
.primaryKey()
|
|
36
|
+
.$defaultFn(() => crypto.randomUUID()),
|
|
37
|
+
name: d.text(),
|
|
38
|
+
email: d.text().unique(),
|
|
39
|
+
emailVerified: d.integer({ mode: "timestamp" }),
|
|
40
|
+
image: d.text(),
|
|
41
|
+
createdAt: d
|
|
42
|
+
.integer({ mode: "timestamp" })
|
|
43
|
+
.default(sql`(unixepoch())`)
|
|
44
|
+
.notNull(),
|
|
45
|
+
updatedAt: d.integer({ mode: "timestamp" }).$onUpdate(() => new Date()),
|
|
46
|
+
}),
|
|
47
|
+
(t) => [
|
|
48
|
+
index("user_name_idx").on(t.name),
|
|
49
|
+
index("user_email_idx").on(t.email),
|
|
50
|
+
]
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
export const session = createTable(
|
|
54
|
+
"session",
|
|
55
|
+
(d) => ({
|
|
56
|
+
sessionToken: d.text().primaryKey(),
|
|
57
|
+
userId: d
|
|
58
|
+
.text()
|
|
59
|
+
.notNull()
|
|
60
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
61
|
+
expires: d.integer({ mode: "timestamp" }).notNull(),
|
|
62
|
+
createdAt: d
|
|
63
|
+
.integer({ mode: "timestamp" })
|
|
64
|
+
.default(sql`(unixepoch())`)
|
|
65
|
+
.notNull(),
|
|
66
|
+
updatedAt: d.integer({ mode: "timestamp" }).$onUpdate(() => new Date()),
|
|
67
|
+
}),
|
|
68
|
+
(t) => [index("session_userId_idx").on(t.userId)]
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
export const account = createTable(
|
|
72
|
+
"account",
|
|
73
|
+
(d) => ({
|
|
74
|
+
provider: d.text().notNull(),
|
|
75
|
+
providerAccountId: d.text().notNull(),
|
|
76
|
+
id_token: d.text(),
|
|
77
|
+
scope: d.text(),
|
|
78
|
+
password: d.text(),
|
|
79
|
+
type: d.text().$type<AdapterAccountType>().notNull(),
|
|
80
|
+
token_type: d.text(),
|
|
81
|
+
session_state: d.text(),
|
|
82
|
+
access_token: d.text(),
|
|
83
|
+
refresh_token: d.text(),
|
|
84
|
+
userId: d
|
|
85
|
+
.text()
|
|
86
|
+
.notNull()
|
|
87
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
88
|
+
expires_at: d.integer(),
|
|
89
|
+
createdAt: d
|
|
90
|
+
.integer({ mode: "timestamp" })
|
|
91
|
+
.default(sql`(unixepoch())`)
|
|
92
|
+
.notNull(),
|
|
93
|
+
updatedAt: d.integer({ mode: "timestamp" }).$onUpdate(() => new Date()),
|
|
94
|
+
}),
|
|
95
|
+
(t) => [
|
|
96
|
+
index("account_userId_idx").on(t.userId),
|
|
97
|
+
primaryKey({ columns: [t.provider, t.providerAccountId] }),
|
|
98
|
+
]
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
export const verificationToken = createTable(
|
|
102
|
+
"verificationToken",
|
|
103
|
+
(d) => ({
|
|
104
|
+
identifier: d.text().notNull(),
|
|
105
|
+
token: d.text().notNull(),
|
|
106
|
+
expires: d.integer({ mode: "timestamp_ms" }).notNull(),
|
|
107
|
+
createdAt: d
|
|
108
|
+
.integer({ mode: "timestamp" })
|
|
109
|
+
.default(sql`(unixepoch())`)
|
|
110
|
+
.notNull(),
|
|
111
|
+
updatedAt: d.integer({ mode: "timestamp" }).$onUpdate(() => new Date()),
|
|
112
|
+
}),
|
|
113
|
+
(t) => [
|
|
114
|
+
index("verification_identifier_idx").on(t.identifier),
|
|
115
|
+
primaryKey({ columns: [t.identifier, t.token] }),
|
|
116
|
+
]
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
export const authenticator = createTable(
|
|
120
|
+
"authenticator",
|
|
121
|
+
(d) => ({
|
|
122
|
+
counter: d.integer().notNull(),
|
|
123
|
+
transports: d.text(),
|
|
124
|
+
credentialID: d.text().notNull().unique(),
|
|
125
|
+
credentialPublicKey: d.text().notNull(),
|
|
126
|
+
credentialDeviceType: d.text().notNull(),
|
|
127
|
+
credentialBackedUp: d.integer({ mode: "boolean" }).notNull(),
|
|
128
|
+
providerAccountId: d.text().notNull(),
|
|
129
|
+
userId: d
|
|
130
|
+
.text()
|
|
131
|
+
.notNull()
|
|
132
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
133
|
+
}),
|
|
134
|
+
(t) => [
|
|
135
|
+
index("authenticator_userId_idx").on(t.userId),
|
|
136
|
+
primaryKey({ columns: [t.userId, t.credentialID] }),
|
|
137
|
+
]
|
|
138
|
+
)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// This is an example schema for PostgreSQL using Drizzle ORM.
|
|
2
|
+
// Learn more at https://orm.drizzle.team/docs/sql-schema-declaration
|
|
3
|
+
|
|
4
|
+
import { sql } from "drizzle-orm"
|
|
5
|
+
import { index, mysqlTableCreator } from "drizzle-orm/mysql-core"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Below is an example of how to create a table with a prefix.
|
|
9
|
+
* This is useful for multi-tenant applications where you want to separate data by tenant.
|
|
10
|
+
*
|
|
11
|
+
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
|
|
12
|
+
*/
|
|
13
|
+
export const createTable = mysqlTableCreator((name) => `project1_${name}`)
|
|
14
|
+
|
|
15
|
+
export const post = createTable(
|
|
16
|
+
"post",
|
|
17
|
+
(d) => ({
|
|
18
|
+
id: d.bigint({ mode: "number" }).primaryKey().autoincrement(),
|
|
19
|
+
name: d.varchar({ length: 255 }).notNull(),
|
|
20
|
+
createdAt: d
|
|
21
|
+
.timestamp({ mode: "date" })
|
|
22
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
23
|
+
.notNull(),
|
|
24
|
+
updatedAt: d.timestamp({ mode: "date" }).$onUpdate(() => new Date()),
|
|
25
|
+
}),
|
|
26
|
+
(t) => [index("post_name_idx").on(t.name)]
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
export const user = createTable(
|
|
30
|
+
"user",
|
|
31
|
+
(d) => ({
|
|
32
|
+
id: d.varchar({ length: 36 }).primaryKey(),
|
|
33
|
+
name: d.varchar({ length: 255 }).notNull(),
|
|
34
|
+
email: d.varchar({ length: 255 }).notNull().unique(),
|
|
35
|
+
emailVerified: d
|
|
36
|
+
.boolean()
|
|
37
|
+
.$defaultFn(() => false)
|
|
38
|
+
.notNull(),
|
|
39
|
+
image: d.text(),
|
|
40
|
+
createdAt: d
|
|
41
|
+
.timestamp({ mode: "date" })
|
|
42
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
43
|
+
.notNull(),
|
|
44
|
+
updatedAt: d.timestamp({ mode: "date" }).$onUpdate(() => new Date()),
|
|
45
|
+
}),
|
|
46
|
+
(t) => [
|
|
47
|
+
index("user_name_idx").on(t.name),
|
|
48
|
+
index("user_email_idx").on(t.email),
|
|
49
|
+
]
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
export const session = createTable(
|
|
53
|
+
"session",
|
|
54
|
+
(d) => ({
|
|
55
|
+
id: d.varchar({ length: 36 }).primaryKey(),
|
|
56
|
+
token: d.varchar({ length: 255 }).notNull().unique(),
|
|
57
|
+
ipAddress: d.text(),
|
|
58
|
+
userAgent: d.text(),
|
|
59
|
+
userId: d
|
|
60
|
+
.varchar({ length: 36 })
|
|
61
|
+
.notNull()
|
|
62
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
63
|
+
expiresAt: d.timestamp().notNull(),
|
|
64
|
+
createdAt: d
|
|
65
|
+
.timestamp({ mode: "date" })
|
|
66
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
67
|
+
.notNull(),
|
|
68
|
+
updatedAt: d.timestamp({ mode: "date" }).$onUpdate(() => new Date()),
|
|
69
|
+
}),
|
|
70
|
+
(t) => [index("session_userId_idx").on(t.userId)]
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
export const account = createTable(
|
|
74
|
+
"account",
|
|
75
|
+
(d) => ({
|
|
76
|
+
id: d.varchar({ length: 36 }).primaryKey(),
|
|
77
|
+
accountId: d.text().notNull(),
|
|
78
|
+
providerId: d.text().notNull(),
|
|
79
|
+
idToken: d.text(),
|
|
80
|
+
scope: d.text(),
|
|
81
|
+
password: d.text(),
|
|
82
|
+
accessToken: d.text(),
|
|
83
|
+
refreshToken: d.text(),
|
|
84
|
+
accessTokenExpiresAt: d.timestamp(),
|
|
85
|
+
refreshTokenExpiresAt: d.timestamp(),
|
|
86
|
+
userId: d
|
|
87
|
+
.varchar({ length: 36 })
|
|
88
|
+
.notNull()
|
|
89
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
90
|
+
createdAt: d
|
|
91
|
+
.timestamp({ mode: "date" })
|
|
92
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
93
|
+
.notNull(),
|
|
94
|
+
updatedAt: d.timestamp({ mode: "date" }).$onUpdate(() => new Date()),
|
|
95
|
+
}),
|
|
96
|
+
(t) => [index("account_userId_idx").on(t.userId)]
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
export const verification = createTable(
|
|
100
|
+
"verification",
|
|
101
|
+
(d) => ({
|
|
102
|
+
id: d.varchar({ length: 36 }).primaryKey(),
|
|
103
|
+
identifier: d.varchar({ length: 255 }).notNull(),
|
|
104
|
+
value: d.text().notNull(),
|
|
105
|
+
expiresAt: d.timestamp().notNull(),
|
|
106
|
+
createdAt: d
|
|
107
|
+
.timestamp({ mode: "date" })
|
|
108
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
109
|
+
.notNull(),
|
|
110
|
+
updatedAt: d.timestamp({ mode: "date" }).$onUpdate(() => new Date()),
|
|
111
|
+
}),
|
|
112
|
+
(t) => [index("verification_identifier_idx").on(t.identifier)]
|
|
113
|
+
)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// This is an example schema for PostgreSQL using Drizzle ORM.
|
|
2
|
+
// Learn more at https://orm.drizzle.team/docs/sql-schema-declaration
|
|
3
|
+
|
|
4
|
+
import { sql } from "drizzle-orm"
|
|
5
|
+
import { index, pgTableCreator } from "drizzle-orm/pg-core"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Below is an example of how to create a table with a prefix.
|
|
9
|
+
* This is useful for multi-tenant applications where you want to separate data by tenant.
|
|
10
|
+
*
|
|
11
|
+
* @see https://orm.drizzle.team/docs/goodies#multi-project-schema
|
|
12
|
+
*/
|
|
13
|
+
export const createTable = pgTableCreator((name) => `project1_${name}`)
|
|
14
|
+
|
|
15
|
+
export const post = createTable(
|
|
16
|
+
"post",
|
|
17
|
+
(d) => ({
|
|
18
|
+
id: d.integer().primaryKey().generatedByDefaultAsIdentity(),
|
|
19
|
+
name: d.varchar({ length: 255 }).notNull(),
|
|
20
|
+
createdAt: d
|
|
21
|
+
.timestamp({ withTimezone: true })
|
|
22
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
23
|
+
.notNull(),
|
|
24
|
+
updatedAt: d.timestamp({ withTimezone: true }).$onUpdate(() => new Date()),
|
|
25
|
+
}),
|
|
26
|
+
(t) => [index("post_name_idx").on(t.name)]
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
export const user = createTable(
|
|
30
|
+
"user",
|
|
31
|
+
(d) => ({
|
|
32
|
+
id: d.text().primaryKey(),
|
|
33
|
+
name: d.text().notNull(),
|
|
34
|
+
email: d.text().notNull().unique(),
|
|
35
|
+
emailVerified: d
|
|
36
|
+
.boolean()
|
|
37
|
+
.$defaultFn(() => false)
|
|
38
|
+
.notNull(),
|
|
39
|
+
image: d.text(),
|
|
40
|
+
createdAt: d
|
|
41
|
+
.timestamp({ withTimezone: true })
|
|
42
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
43
|
+
.notNull(),
|
|
44
|
+
updatedAt: d.timestamp({ withTimezone: true }).$onUpdate(() => new Date()),
|
|
45
|
+
}),
|
|
46
|
+
(t) => [
|
|
47
|
+
index("user_name_idx").on(t.name),
|
|
48
|
+
index("user_email_idx").on(t.email),
|
|
49
|
+
]
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
export const session = createTable(
|
|
53
|
+
"session",
|
|
54
|
+
(d) => ({
|
|
55
|
+
id: d.text().primaryKey(),
|
|
56
|
+
token: d.text().notNull().unique(),
|
|
57
|
+
ipAddress: d.text(),
|
|
58
|
+
userAgent: d.text(),
|
|
59
|
+
userId: d
|
|
60
|
+
.text()
|
|
61
|
+
.notNull()
|
|
62
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
63
|
+
expiresAt: d.timestamp().notNull(),
|
|
64
|
+
createdAt: d
|
|
65
|
+
.timestamp({ withTimezone: true })
|
|
66
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
67
|
+
.notNull(),
|
|
68
|
+
updatedAt: d.timestamp({ withTimezone: true }).$onUpdate(() => new Date()),
|
|
69
|
+
}),
|
|
70
|
+
(t) => [index("session_userId_idx").on(t.userId)]
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
export const account = createTable(
|
|
74
|
+
"account",
|
|
75
|
+
(d) => ({
|
|
76
|
+
id: d.text().primaryKey(),
|
|
77
|
+
accountId: d.text().notNull(),
|
|
78
|
+
providerId: d.text().notNull(),
|
|
79
|
+
idToken: d.text(),
|
|
80
|
+
scope: d.text(),
|
|
81
|
+
password: d.text(),
|
|
82
|
+
accessToken: d.text(),
|
|
83
|
+
refreshToken: d.text(),
|
|
84
|
+
accessTokenExpiresAt: d.timestamp(),
|
|
85
|
+
refreshTokenExpiresAt: d.timestamp(),
|
|
86
|
+
userId: d
|
|
87
|
+
.text()
|
|
88
|
+
.notNull()
|
|
89
|
+
.references(() => user.id, { onDelete: "cascade" }),
|
|
90
|
+
createdAt: d
|
|
91
|
+
.timestamp({ withTimezone: true })
|
|
92
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
93
|
+
.notNull(),
|
|
94
|
+
updatedAt: d.timestamp({ withTimezone: true }).$onUpdate(() => new Date()),
|
|
95
|
+
}),
|
|
96
|
+
(t) => [index("account_userId_idx").on(t.userId)]
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
export const verification = createTable(
|
|
100
|
+
"verification",
|
|
101
|
+
(d) => ({
|
|
102
|
+
id: d.text().primaryKey(),
|
|
103
|
+
identifier: d.text().notNull(),
|
|
104
|
+
value: d.text().notNull(),
|
|
105
|
+
expiresAt: d.timestamp().notNull(),
|
|
106
|
+
createdAt: d
|
|
107
|
+
.timestamp({ withTimezone: true })
|
|
108
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
109
|
+
.notNull(),
|
|
110
|
+
updatedAt: d.timestamp({ withTimezone: true }).$onUpdate(() => new Date()),
|
|
111
|
+
}),
|
|
112
|
+
(t) => [index("verification_identifier_idx").on(t.identifier)]
|
|
113
|
+
)
|