Repository: directus/directus
File: api/src/services/fields.ts (TypeScript)

Code before:

		if (defaultValue) {
			const newDefaultValueIsString = typeof defaultValue === 'string';
			const newDefaultIsNowFunction = newDefaultValueIsString && defaultValue.toLowerCase() === 'now()';
			const newDefaultIsCurrentTimestamp = newDefaultValueIsString && defaultValue === 'CURRENT_TIMESTAMP';
			const newDefaultIsSetToCurrentTime = newDefaultIsNowFunction || newDefaultIsCurrentTimestamp;

			const newDefaultIsTimestampWithPrecision =
				newDefaultValueIsString && defaultValue.includes('CURRENT_TIMESTAMP(') && defaultValue.includes(')');

			if (newDefaultIsSetToCurrentTime) {
				column.defaultTo(this.knex.fn.now());
			} else if (newDefaultIsTimestampWithPrecision) {
				const precision = defaultValue.match(REGEX_BETWEEN_PARENS)![1];
				column.defaultTo(this.knex.fn.now(Number(precision)));
			} else {
				column.defaultTo(defaultValue);
			}
		} else {
			column.defaultTo(null);
		}

		if (field.schema?.is_nullable && (!existing || existing.is_nullable === false)) {
			column.nullable();
		} else if (field.schema?.is_nullable === false && existing && existing.is_nullable === true) {
			column.notNullable();
		}

		if (field.schema?.is_primary_key) {
			column.primary().notNullable();
		} else if (!existing?.is_primary_key) {
			// primary key will already have unique/index constraints
			if (field.schema?.is_unique === true) {
				if (!existing || existing.is_unique === false) {
					column.unique();
				}
			} else if (field.schema?.is_unique === false) {
				if (existing && existing.is_unique === true) {
					table.dropUnique([field.field]);
				}
			}

			if (field.schema?.is_indexed === true && !existing?.is_indexed) {
				column.index();
			} else if (field.schema?.is_indexed === false && existing?.is_indexed) {
				table.dropIndex([field.field]);
			}
		}

		if (existing) {
			column.alter();

Review comment (suggestion):
I was not sure if this was an intentional default or not, I assumed it was not and is a leftover artifact from when we changed to not sending all data from the `Data Studio`

IMO we should not set it unless specifically requested. If we leave it as is `Oracle` errors on most changes as it attempts to set the column to `NOT NULL` again which is not allowed.

Code after:

		if (defaultValue) {
			const newDefaultValueIsString = typeof defaultValue === 'string';
			const newDefaultIsNowFunction = newDefaultValueIsString && defaultValue.toLowerCase() === 'now()';
			const newDefaultIsCurrentTimestamp = newDefaultValueIsString && defaultValue === 'CURRENT_TIMESTAMP';
			const newDefaultIsSetToCurrentTime = newDefaultIsNowFunction || newDefaultIsCurrentTimestamp;
			const newDefaultIsAFunction = newDefaultValueIsString && ALLOWED_DB_DEFAULT_FUNCTIONS.includes(defaultValue);

			const newDefaultIsTimestampWithPrecision =
				newDefaultValueIsString && defaultValue.includes('CURRENT_TIMESTAMP(') && defaultValue.includes(')');

			if (newDefaultIsSetToCurrentTime) {
				column.defaultTo(this.knex.fn.now());
			} else if (newDefaultIsTimestampWithPrecision) {
				const precision = defaultValue.match(REGEX_BETWEEN_PARENS)![1];
				column.defaultTo(this.knex.fn.now(Number(precision)));
			} else if (newDefaultIsAFunction) {
				column.defaultTo(this.knex.raw(defaultValue));
			} else {
				column.defaultTo(defaultValue);
			}
		} else {
			column.defaultTo(null);
		}

		const isNullable = field.schema?.is_nullable ?? existing?.is_nullable ?? true;

		if (isNullable) {
			column.nullable();
		} else {
			column.notNullable();
		}

		if (field.schema?.is_primary_key) {
			column.primary().notNullable();
		} else if (!existing?.is_primary_key) {
			// primary key will already have unique/index constraints
			if (field.schema?.is_unique === true) {
				if (!existing || existing.is_unique === false) {
					column.unique();
				}
			} else if (field.schema?.is_unique === false) {
				if (existing && existing.is_unique === true) {
					table.dropUnique([field.field]);
				}
			}

			if (field.schema?.is_indexed === true && !existing?.is_indexed) {
				column.index();
			} else if (field.schema?.is_indexed === false && existing?.is_indexed) {
				table.dropIndex([field.field]);